⑴ 怎麼把本地文件上傳tomcat虛擬路徑配置
在tomcat6版本中:
1、【官方文檔】本人不推薦。
在tomcatconf下server.xml中找到
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
在其中添加:
<Context path="" docBase="換成你的路徑" reloadable="true"></Context>
這的docBase要改成你的項目目錄。
2、 不修改server.xml【推薦使用此方法】
在tomcat文件夾的conf"catalina"localhost(對於Tomcat6版本及其以上,需要自己創建catalina和localhost這兩個文件夾)下新建一個xml文件。內容為
<?xml version="1.0" encoding="UTF-8"?>
<Context
docBase="換成你的路徑"
reloadable="true">
</Context>
文件名改成你自己的譬如http://localhost:8080/bbs ,文件名就為bbs.xml
其他配置:
打開 Tomcat6.0"conf"web.xml 文件,找到:
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
把false設成true保存,重啟Tomcat,讓tomcat6支持文件列表顯示。
⑵ tomcat上傳文件問題
第一步:需要先創建一個server,可以通過windows中的show view,之後找到server,
第二步:在server窗口中右擊,選擇」new-server「,之後創建好tomcat server。
第三步:雙擊創建的server,進入server設置界面,設置Server Location,選擇編譯路徑是」Use Tomcat「即可切換到Tomcat的路徑,保存。
第四步:之後將server項目添加到此server下,這樣就完成了部署到Tomcat下。
⑶ 怎麼把文件上傳到tomcat伺服器
一,將項目導出成WAR包,而後將該包直接復制到tomcat的webapp目錄下,這樣就可以訪問了 二,配置tomcat 修改${tomcat.home}\conf\server.xml文件.在Host節點下增加如下參考代碼: docBase:指向項目的根目錄所在的路徑, 由於將項目打成了war包,所
⑷ 問一下如何上傳文件到tomcat的webapps文件夾中
首先 你的明白 文件上傳的原理
jsp 頁面 通過表單 屬性設置input type=file 是告訴伺服器 這里 請求的是個文件
伺服器 通過二進制 讀取文件 然後 在寫文件
所以你設定好寫文件的路徑 不就可以了么
其次 我想你的工程 應該是部署在webapps下吧 一般 文件上傳都是存放在工程相應目錄下的
⑸ android伺服器怎麼發布在tomcat上
怎麼讓你的Android手機訪問你在電腦上發布的Tomcat項目,也就是讓你的電腦當主機??
辦法如下:
1、首先你部署版你的項權目,啟動伺服器,然後通過瀏覽器去訪問,如果你訪問成功,那就說明項目和tomcat沒有問題。
2、下載一個Connectify Hotspot,地址如下:http://www.connectify.me/hotspot/,它的功能就是讓你的電腦的網變成WIFI熱點,當然是筆記本電腦才有用,台式沒有用的。然後你的手機通過WIFI就可以連接到這個網,這與這個東西怎麼用,我就不介紹了,網上有。
3、然後將滑鼠放在在它的最小化圖標上,它會顯示一個ip:比如192.168.249.1,(這個是隨機生成的,並非我電腦的ip)
⑹ 怎麼向tomcat伺服器上傳文件
1.將tomcat環境搭配好
path中加入:
%CATALINA_HOME%\lib;%CATALINA_HOME%\bin;
2.修改tomcat中config/server.xml
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
<Context docBase="D:\workspace\picture\target\mvc-basic.war" path="/picture"/>
</Host>
添加紅色部分
docBase中要為項目打包成的war文件。
path隨意
啟動tomcat bin\startup.bat,如果這時tomcat一閃而過,表示啟動異常,很可能是配置或者server.xml出問題了。
注意:有時即使更改了war文件裡面的文件,程序仍然沒有任何變化,這個時候要把apache-tomcat-7.0.11\webapps下的項目文件給刪除,再重新啟動tomcat。
由於我是用eclipse開發的,下面那段紅色線表示我發布的位置,wtpwebapps下,我試過,只有把圖片放在D:\workspace
\.metadata\.plugins\org.eclipse.wst.server.core\tmp4\wtpwebapps\ROOT裡面項目
才能讀取到圖片。而如果將項目打包成war後,更改<Context docBase="D:\workspace\picture\target\mvc-basic.war" path="/picture"/>更tomcat的根目錄是apache-tomcat-7.0.11\webapps,只需要在這個下面建立images目錄,把圖片往裡面存就行了。
3.代碼
[java] view plain
private static final String PICTURE_WEB_INF = "/picture/WEB-INF";
private static final String ROOT_IMAGES_PICTURE = "/ROOT/images/picture";
private static final String IMAGES_PICTURE = "/images/picture";
@RequestMapping(value = "/add",method = RequestMethod.POST)
public String save(Picture picture, HttpServletRequest request) {
this.FileAndSaveFile(request, picture);
this.pictureService.save(picture);
return "redirect:/index";
}
private void FileAndSaveFile(HttpServletRequest request, Picture material) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
for (Map.Entry<String, MultipartFile> entity : multipartRequest.getFileMap().entrySet()) {
MultipartFile mf = entity.getValue();
String uuid = UUID.randomUUID().toString();
String classPath = this.getClass().getClassLoader().getResource("/").getPath();
try {
classPath =URLDecoder.decode(classPath, "gb2312");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
classPath = classPath.split(PICTURE_WEB_INF)[0];
File pictureFile = new File(classPath+ROOT_IMAGES_PICTURE);
if(!pictureFile.exists()){
pictureFile.mkdirs();
}
String path = pictureFile.getPath();
String ext = null;
try {
if (null == mf || mf.isEmpty() || null == mf.getInputStream() || mf.getSize() > 40000000) {
return;
}
ext = Files.getFileExtension(mf.getOriginalFilename());
if(classPath.indexOf("wtpwebapps")!=-1){
path = classPath+ROOT_IMAGES_PICTURE;
}else{
path = classPath+IMAGES_PICTURE;
}
File f = new File(path +"/" + uuid + "." + ext);
Files.createParentDirs(f);
FileCopyUtils.(mf.getBytes(), f);
material.setFilePath(IMAGES_PICTURE + "/" + uuid + "." + ext);
material.setFileName(mf.getOriginalFilename());
} catch (IOException e) {
e.printStackTrace();
}
}
}
因為使用eclipse開發的,所以會是indexof(wtpwebapps),其他的開發工具要看情況。
jsp:
另外img src好像不支持用絕對路徑,顯示不出來,我也不知道為什麼,網路了很多都沒說,但是絕對路徑應該是不可行的,因為有時需要移植什麼的容易出現問題。
[html] view plain
<head>
<title>圖片列表</title>
<script language="javascript" src="./resources/js/jquery-1.8.3.js"> </script>
<script language="javascript" src="./resources/js/jquery.validate.min.js"> </script>
<script language="javascript" src="./resources/js/picture/add.js"> </script>
</head>
<body>
<form action = "<c:url value = "/picture/add"></c:url>" method = "post" id="add_form" enctype="multipart/form-data">
<table class="tab01">
<tr>
<td class="name">名稱:</td>
<td><input id = "name" type="text" class="text_input" name="title" placeholder="標題"/></td>
<td><label for="title" class="error" generated="true" style="color:red;font-size:12px;"></label></td>
</tr>
<tr>
<td class="name">上傳圖片:</td>
<td><input type="file" class="text_input" name="file" id="file" placeholder="上傳圖片"/></td>
<td><label for="file" class="error" generated="true" style="color:red;font-size:12px;"></label></td>
</tr>
<tr>
<td> </td>
<td colspan="2">
<input type="submit" class="button" id="submitButton" value="提交" name="reset" />
<input type="reset" class="button" value="重置" name="reset" />
</td>
</tr>
</table>
</form>
<br/><br/><br/>
<c:forEach items = "${pictureList }" var = "picture">
<p>${picture.title }</p>
<div><img src="${picture.filePath }" width = "500" height = "500" BORDER="0" ALT="無圖片"/>
</div>
</c:forEach>
</body>
[javascript] view plain
$(function(){
jQuery.validator.messages.required = "<span class='error' generated='true' style='color: red; font-size: 12px;'>*請填寫此內容</span>";
jQuery.validator.messages.maxlength = "<span class='error' generated='true' style='color: red; font-size: 12px;'>*已達到最大字元數 </span>";
jQuery.validator.messages.accept = "<span class='error' generated='true' style='color: red; font-size: 12px;'>*請輸入擁有合法後綴名的字元串 </span>";
$("#add_form").validate({
rules : {
title : {required : true, maxlength :200 },
file : {required : true}
}
});
$("input[type='file']").change(function(){
alert(this.files[0].size);
if(this.files[0].size>300*1024){
alert("圖片太大!!圖片不大於300KB");
$("#submitButton").attr("disabled","disabled");
}else{
$("#submitButton").removeAttr("disabled");
}
});
$("#add_form").submit(function() {
var filepath=$("input[name='file']").val();
var extStart=filepath.lastIndexOf(".");
var ext=filepath.substring(extStart,filepath.length).toUpperCase();
if(ext!=".BMP"&&ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
alert("圖片限於bmp,png,gif,jpeg,jpg格式");
return false;
}
return true;
});
});