當前位置:首頁 » 文件管理 » tomcat上傳文件大小

tomcat上傳文件大小

發布時間: 2022-09-15 01:42:43

1. 使用file上傳的文件在tomcat的哪裡一次可以上傳多大的我上傳的是視頻文件

你這種上傳直接上傳到tomcat里很不好,既然你會用file上傳你可以把上傳的路徑傳到你的項目里,這樣比較好點,上傳的大小你可以通過設置file的屬性和方法來做的。

2. 如何解決nginx+tomcat文件上傳問題

最常用的方法是通過設置nginx的client_max_body_size解決nginx+php上傳大文件,主要是設置上傳文件大小和php腳本運行時長即可。

3. 怎麼向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;
});
});

4. tomcat只有1g內存,要上傳2g文件,怎麼辦

先試試這個:
-Xms64m
-Xmx256m
-XX:PermSize=128M
-XX:MaxNewSize=256m
-XX:MaxPermSize=256m

5. android開發:怎樣實現上傳文件到Tomcat伺服器上,求可執行的代碼,越簡潔越好

伺服器端寫個servlet,然後在doPost()方法里處理客戶端上傳的文件,大概代碼:

DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1024 * 1024); // 設置最多隻允許在內存中存儲的數據, 單位:位元組
factory.setRepository(cachepath); // 設置一旦文件大小超過設定值時數據存放的目錄

ServletFileUpload srvFileUpload = new ServletFileUpload(factory);
srvFileUpload.setSizeMax(1024 * 1024 * 1024); // 設置允許用戶上傳文件大小, 單位:位元組

// 開始讀取上傳信息
List fileItems = null;
try {
fileItems = srvFileUpload.parseRequest(request);
} catch (Exception e) {
System.out.println("獲取上傳信息。。。。。。失敗");
}

// 依次處理每個上傳的文件
Iterator iter = fileItems.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next(); // 忽略其他不是文件域的所有表單信息
if (!item.isFormField()) {
// 取出文件域的所有表單信息
} else {
// 取出不是文件域的所有表單信息
}
}

6. 文件上傳大小錯誤

在struts.xml配置,把分給我吧^_^

7. 怎麼用Tomcat上傳大文件(2G左右)

對於你這個問題,我感覺不是好方法。第一tomcat應用伺服器,如果傳入這么大文件對性能和存儲都是個考驗。這不是個好方法。如果你確實要這樣,可以壓縮分為幾個文件,我想這樣揮毫很多。其實更好的方式是建立一個FTP服務,上傳下載都很方便。希望對你有所幫助吧。

8. 我用commons-fileupload設置上傳文件大小時遇到一個問題。upload.setFil

fileupload有兩個設置:

  1. upload.setFileSizeMax(1024*1024*100); //設置上傳的單個文件的最大位元組數為100M

  2. upload.setSizeMax(1024*1024*1024); //設置整個表單的最大位元組數為1G

setFileSizeMax意思是單個文件的大小,setSizeMax表示表單的總大寫,建議寫大一點就不會報錯了。

9. 上傳文件失敗,具體原因:上傳的文件超過大小限制,請上傳小於 1024k的文件

伺服器默認設置沒改導致的
NGINX、Tomcat都有相關設置
網路搜一下 上傳文件超過1M報錯 就知道了,改下參數並重啟服務就行了。

10. tomcat本地伺服器,上傳圖片成功後隔天查看圖片就不顯示啦為什麼求解

看看你有沒有修改IIS默認上傳文件大小限制200K,如果沒有的話那圖片超過200K,IIS會不容許你上傳

熱點內容
pcl如何創造有mods伺服器 發布:2024-10-10 23:16:18 瀏覽:851
證券中的ftp 發布:2024-10-10 23:16:14 瀏覽:483
風行視頻緩存 發布:2024-10-10 23:02:55 瀏覽:602
武漢學java 發布:2024-10-10 23:00:52 瀏覽:359
php入門到精通 發布:2024-10-10 22:51:27 瀏覽:526
我的世界基岩版的伺服器怎麼進入 發布:2024-10-10 22:45:32 瀏覽:360
什麼是保險櫃主密碼 發布:2024-10-10 22:39:54 瀏覽:660
sql臨時表效率 發布:2024-10-10 22:24:37 瀏覽:503
linux搭建mc伺服器搭建 發布:2024-10-10 21:58:38 瀏覽:984
ubuntu解壓工具 發布:2024-10-10 21:58:27 瀏覽:231