練功房推薦書單

  • 猛虎出柙雙劍合璧版:最新 OCA / OCP Java SE 7 Programmer 專業認證
  • 流浪教師存零股存到3000萬
  • SCJP 6.0認證教戰手冊(第二版)Oracle Certified Professional Java Programmer(附光碟)
  • 小資女艾蜜莉:我的資產翻倍存股筆記
JSP精選實用範例(二):檔案上傳  RSS feed
討論區首頁 » 網頁程式設計 Web Development
發表人 內容
lionsgogo

十級學員

註冊時間: 2010-03-07 20:11:11
文章: 3
離線
請問如果將檔案上傳後

如何查詢<將檔案名稱顯示出來>

還有怎麼寫一個網頁

將查詢到想要的檔案下載下來

謝謝你

幫這我很大
andowson

七段學員
[Avatar]

註冊時間: 2007-01-02 22:20:40
文章: 704
來自: 台北
離線
lionsgogo wrote:org.apache.jasper.JasperException: Exception in JSP: /fileupload.jsp:74

71: fileName= FilenameUtils.getName(fileName);
72: out.println("fileName saved="+fileName+"<br>");
73: File uploadedFile = new File(saveDirectory, fileName);
74: item.write(uploadedFile);
75: }
76: }
77: }

為什麼會有錯誤??

lionsgogo您好:
請您檢查一下在您網頁的根目錄下有沒有/upload這個目錄?
如果沒有的話跑出來的錯誤訊息應該會類似這樣子
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /fileupload.jsp at line 74

71: fileName= FilenameUtils.getName(fileName);
72: out.println("fileName saved="+fileName+"<br>");
73: File uploadedFile = new File(saveDirectory, fileName);
74: item.write(uploadedFile);
75: }
76: }
77: }


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:404)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.io.FileNotFoundException: D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\examples\upload\2009蓮藕粉訂單.txt (系統找不到指定的路徑。)
java.io.FileOutputStream.open(Native Method)
java.io.FileOutputStream.<init>(Unknown Source)
java.io.FileOutputStream.<init>(Unknown Source)
org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:416)
org.apache.jsp.fileupload_jsp._jspService(fileupload_jsp.java:133)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20


請手動建立它,如果是在Linux上請設定為可寫入的權限(chmod 777 upload)。

分享經驗 累積智慧
[WWW] [MSN]
mylipton

十級學員

註冊時間: 2010-05-22 23:28:23
文章: 6
離線
您好
想請問一下,我用fileupload_control.jsp這個範例程式傳上去的檔案的檔名會變成亂碼
有人知道這是哪裡有問題嗎


andowson

七段學員
[Avatar]

註冊時間: 2007-01-02 22:20:40
文章: 704
來自: 台北
離線
mylipton您好:
請問您是在什麼系統環境下執行所產生的問題? 請您提供更多資訊以便大家可以較快得幫忙您。例如
OS版本:
Servlet Container版本:
JDK版本:
上傳前檔案名稱:
上傳後檔案名稱:
參考資料:附上錯誤畫面及有錯誤的程式原始碼。
另外也請您參考本篇文章先前的討論內容尋找解答。

分享經驗 累積智慧
[WWW] [MSN]
mylipton

十級學員

註冊時間: 2010-05-22 23:28:23
文章: 6
離線
andowson謝謝
我解決了上傳檔名的問題
雖然也不清楚怎麼改好的
就是把big5 UTF-8 那些亂試
終於試到可以
shyk

十級學員

註冊時間: 2010-09-14 13:04:43
文章: 1
離線
andowsonsup您好:
我用了fileupload_streaming.html後,檔案並沒上傳,瀏覽器直接顯示成:
------------------------------
isMultipart=true
fieldName=file
fileName=1.jpg
contentType=image/jpeg
isInMemory=true
sizeInBytes=782266
fileName to be saved=1.jpg
filedesc=
----------------------------------
不知問題要如何解決??
但我在TOMCAT上是OK的.
OS版本:windows
Servlet Container版本: glassfish
JDK版本: jdk1.6.0_21
上傳前檔案名稱: 1.jpg
上傳後檔案名稱: 1.jpg
andowson

七段學員
[Avatar]

註冊時間: 2007-01-02 22:20:40
文章: 704
來自: 台北
離線
shyk您好:
我下載的是本主題的第二篇文章的附檔fileupload_streaming.html及fileupload_streaming.jsp,然後安裝GlassFish Server Open Source Edition 3.0.1(安裝在C:\glassfishv3),經過實際測試顯示的畫面如下:
------------------------------
isMultipart=true
fieldName=file
fileName=1.jpg
contentType=image/jpeg
fileName saved=1.jpg
filedesc=
------------------------------
檔案有出現在upload資料夾下,實際的路徑是:
C:\glassfishv3\glassfish\domains\domain1\applications\example\upload
所以,在GlassFish應該也是沒問題的。(其實,過程中有遇到一個小狀況就是,我用Eclipse把所有的檔案包成一個example.war,原本的example.war裡面明明有放一個upload的空目錄,但是佈署後,該目錄卻消失了,造成上傳失敗,手動建立後,再上傳就成功了)

比對你的輸出畫面文字跟我的不太相同,不知道您下載的是哪一篇文章的附檔?您可以檢查一下GlassFish的logs目錄下面的server.log,看看錯誤訊息為何,應該就可以知道問題在哪邊了。

分享經驗 累積智慧
[WWW] [MSN]
aauggogogo

十級學員

註冊時間: 2011-01-03 14:53:24
文章: 2
離線
請問版大我下載第二個程式,但在上傳時如果檔名是中文會產生??的亂碼,檔案除了檔名外皆正常上傳。
也試過用不同的檔名編碼來儲存,但是都無法成功儲存中文檔名。

OS: solaris10
Web Server: Sun GlassFish Enterprise Server v2.1.1

感謝
andowson

七段學員
[Avatar]

註冊時間: 2007-01-02 22:20:40
文章: 704
來自: 台北
離線
aauggogogo您好:
我想您是由Windows環境將中文檔名的檔案上傳到Solaris的檔案系統,然後看到上傳的檔名變成??的樣子吧?

由於我目前手邊沒有Solaris 10的環境,所以我改用Linux環境的經驗來說明,供您參考:

首先,參考這篇文章JVM and OS System Properties,將下列的程式碼編譯成SysProperties.class

SysProperties.java:
import java.util.Properties;

public class SysProperties {
   public static void main(String[] args) {
      Properties sysProps = System.getProperties();
      sysProps.list(System.out);
   }
}


然後執行
java SysProperties


可以得到類似下面的輸出
smilie Windows:
-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C:\Program Files\Java\jdk1.6.0_23\jre...
java.vm.version=19.0-b09
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=TW
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=Service Pack 3
java.vm.specification.name=Java Virtual Machine Specification
user.dir=D:\workspace\test
java.runtime.version=1.6.0_23-b05
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\jdk1.6.0_23\jre...
os.arch=x86
java.io.tmpdir=C:\DOCUME~1\user\LOCALS~1\Temp\
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows XP
sun.jnu.encoding=MS950
java.library.path=C:\Program Files\Java\jdk1.6.0_23\bin...
java.specification.name=Java Platform API Specification
java.class.version=50.0
sun.management.compiler=HotSpot Client Compiler
os.version=5.1
user.home=C:\Documents and Settings\user
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=MS950
java.specification.version=1.6
user.name=andowson
java.class.path=D:\workspace\test\bin
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=C:\Program Files\Java\jdk1.6.0_23\jre
java.specification.vendor=Sun Microsystems Inc.
user.language=zh
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode, sharing
java.version=1.6.0_23
java.ext.dirs=C:\Program Files\Java\jdk1.6.0_23\jre...
sun.boot.class.path=C:\Program Files\Java\jdk1.6.0_23\jre...
java.vendor=Sun Microsystems Inc.
file.separator=\
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.desktop=windows
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+m...

smilie Linux:
[andowson@scm ~]$ java SysProperties
-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=/usr/java/jdk1.6.0_23/jre/lib/i386
java.vm.version=19.0-b09
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=:
java.vm.name=Java HotSpot(TM) Server VM
file.encoding.pkg=sun.io
user.country=TW
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=unknown
java.vm.specification.name=Java Virtual Machine Specification
user.dir=/home/andowson
java.runtime.version=1.6.0_23-b05
java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment
java.endorsed.dirs=/usr/java/jdk1.6.0_23/jre/lib/endorsed
os.arch=i386
java.io.tmpdir=/tmp
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
os.name=Linux
sun.jnu.encoding=UTF-8
java.library.path=/usr/java/jdk1.6.0_23/jre/lib/i386/se...
java.specification.name=Java Platform API Specification
java.class.version=50.0
sun.management.compiler=HotSpot Tiered Compilers
os.version=2.6.18-194.11.1.el5
user.home=/home/andowson
user.timezone=
java.awt.printerjob=sun.print.PSPrinterJob
file.encoding=UTF-8
java.specification.version=1.6
user.name=andowson
java.class.path=.
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=/usr/java/jdk1.6.0_23/jre
java.specification.vendor=Sun Microsystems Inc.
user.language=zh
java.vm.info=mixed mode
java.version=1.6.0_23
java.ext.dirs=/usr/java/jdk1.6.0_23/jre/lib/ext:/us...
sun.boot.class.path=/usr/java/jdk1.6.0_23/jre/lib/resourc...
java.vendor=Sun Microsystems Inc.
file.separator=/
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...
sun.cpu.endian=little
sun.io.unicode.en

然後觀察file.encoding這個系統屬性的值,可以發現在Windows上是MS950,在Linux上是UTF-8,也就是說JVM預設的編碼將會採用MS950和UTF-8來處理檔案的I/O。故通常都會出現一些錯誤訊息,例如File Not Found或寫檔時,檔名看到一堆??和亂碼。

解決的方法:
目前我是將Linux的預設編碼改為Big5,修改/etc/sysconfig/i18n( smilie 需要重開機reboot OS):
LANG="zh_TW.Big5"

另外一種方式(沒試過請自行確認)是啟動JVM時加上-Dfile.encoding=MS950或-Dfile.encoding=Big5

參考資料:
http://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding
 檔案名稱 SysProperties.class [Disk] 下載
 描述 懶得自己編譯者可以直接下載此檔案
 檔案大小 632 bytes
 下載次數:  3 次

 檔案名稱 SysProperties.java [Disk] 下載
 描述 取得JVM和OS系統屬性
 檔案大小 225 bytes
 下載次數:  1 次


分享經驗 累積智慧
[WWW] [MSN]
aauggogogo

十級學員

註冊時間: 2011-01-03 14:53:24
文章: 2
離線
目前server字集為ISO646-US,由於某些原因,無法允許改變字集。
因為沒轍了,所以目前想改其他方式(資料庫存中文檔名)解決。
感謝andowson大大的回覆。
kisskevin524

十級學員

註冊時間: 2010-05-25 10:23:59
文章: 3
離線
可以請問一下可以把上傳路徑不要設在tomcat底下嗎?
可以自己設定檔案路徑嗎?
例如c:\upload
謝謝!!
andowson

七段學員
[Avatar]

註冊時間: 2007-01-02 22:20:40
文章: 704
來自: 台北
離線
中文檔名上傳後變成亂碼或??的問題可以透過指定來源表單的編碼方式修正,另外上傳目錄也可以修改到Tomcat以外的目錄,例如C:\upload下(目錄不存在時也可以自動建立)
首先將來源表單的charset設為UTF-8
fileupload_streaming.html:
<html>
<head>
<title>File Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><font size="5"color="#FF0000"><b>檔案上傳</b></font></p>

<form name="upload" enctype="multipart/form-data" method="post" action="fileupload_streaming.jsp"> 
<p>上傳檔案: <input type="file" name="file" size="20" maxlength="20"> </p>
<p>檔案說明: <input type="text" name="filedesc" size="30" maxlength="50"> </p>
<p> <input type="submit"value="上傳"> <input type="reset" value="清除"> </p>
</form>

</body>
</html>

處理上傳的程式加上request.setCharacterEncoding(encoding);
fileupload_streaming.jsp:
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="java.io.*"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.fileupload.util.Streams"%>
<%@ page import="org.apache.commons.io.FilenameUtils"%>
<%
    //String saveDirectory = application.getRealPath("/upload");
    // Change save direcoty to another place outside of Tomcat
    String saveDirectory = "C:/upload";
    File dir = new File(saveDirectory);
    if (!dir.exists()) {
    	boolean success = dir.mkdir();
        if (success) {
            System.out.println("Directory: " + saveDirectory + " created");
        } 
    }
    
    out.println("file.encoding=" + System.getProperty("file.encoding") + "<br>");
        
    // Solve Chinese filename problem: use original form encoding
    String encoding = "UTF-8";
    request.setCharacterEncoding(encoding);
    
    // Check that we have a file upload request
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    out.println("isMultipart=" + isMultipart + "<br>");
    
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload();

    //Create a progress listener
    ProgressListener progressListener = new ProgressListener(){
       private long megaBytes = -1;
       public void update(long pBytesRead, long pContentLength, int pItems) {
           long mBytes = pBytesRead / 1000000;
           if (megaBytes == mBytes) {
               return;
           }
           megaBytes = mBytes;
           System.out.println("We are currently reading item " + pItems);
           if (pContentLength == -1) {
               System.out.println("So far, " + pBytesRead + " bytes have been read.");
           } else {
               System.out.println("So far, " + pBytesRead + " of " + pContentLength
                                  + " bytes have been read.");
           }
       }
    };
    upload.setProgressListener(progressListener);

    // Parse the request
    FileItemIterator iter = upload.getItemIterator(request);
    while (iter.hasNext()) {
        FileItemStream item = iter.next();
        String name = item.getFieldName();
        InputStream stream = item.openStream();
        if (item.isFormField()) {
            String value = Streams.asString(stream, encoding);
            out.println(name + "=" + value + "<br>");
        } else {
            System.out.println("File field " + name + " with file name "
                + item.getName() + " detected.");
            // Process the input stream
            String fieldName = item.getFieldName();
            String fileName = item.getName();
            String contentType = item.getContentType();
            out.println("fieldName=" + fieldName + "<br>");
            out.println("fileName=" + fileName + "<br>");
            out.println("contentType=" + contentType + "<br>");
            if (fileName != null && !"".equals(fileName)) {
                fileName = FilenameUtils.getName(fileName);
                out.println("fileName saved=" + fileName + "<br>");
                File uploadedFile = new File(saveDirectory, fileName);
                FileOutputStream uploadedFileStream = 
                    new FileOutputStream(uploadedFile);
                Streams.copy(stream, uploadedFileStream, true);
            }
        }
    }              
%>
 檔案名稱 fileupload_streaming.jsp [Disk] 下載
 描述 檔案上傳處理程式
 檔案大小 3 Kbytes
 下載次數:  15 次

 檔案名稱 fileupload_streaming.html [Disk] 下載
 描述 檔案上傳表單
 檔案大小 575 bytes
 下載次數:  14 次


分享經驗 累積智慧
[WWW] [MSN]
kisskevin524

十級學員

註冊時間: 2010-05-25 10:23:59
文章: 3
離線
請問一下
大大有做過上傳過上百mb的檔案嗎
上傳大檔似乎會timeout
謝謝!!
andowson

七段學員
[Avatar]

註冊時間: 2007-01-02 22:20:40
文章: 704
來自: 台北
離線
實際測試上傳一個1GB多的檔案,確實會出現Read timed out的結果:
So far, 1069001476 of 1073742116 bytes have been read.
We are currently reading item 1
So far, 1070000168 of 1073742116 bytes have been read.
We are currently reading item 1
So far, 1071002992 of 1073742116 bytes have been read.
We are currently reading item 1
So far, 1072001684 of 1073742116 bytes have been read.
We are currently reading item 1
So far, 1073000376 of 1073742116 bytes have been read.
一月 16, 2012 2:25:28 上午 org.apache.catalina.core.StandardWrapperValve invoke
嚴重: Servlet.service() for servlet [jsp] in context with path [] threw exception [An exception occurred processing JSP page /fileupload_streaming.jsp at line 65

62:                 File uploadedFile = new File(saveDirectory, fileName);
63:                 FileOutputStream uploadedFileStream =
64:                     new FileOutputStream(uploadedFile);
65:                 Streams.copy(stream, uploadedFileStream, true);
66:             }
67:         }
68:     }


Stacktrace:] with root cause
java.net.SocketTimeoutException: Read timed out
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at org.apache.coyote.ajp.AjpProcessor.read(AjpProcessor.java:309)
        at org.apache.coyote.ajp.AjpProcessor.readMessage(AjpProcessor.java:364)
        at org.apache.coyote.ajp.AjpProcessor.receive(AjpProcessor.java:331)
        at org.apache.coyote.ajp.AbstractAjpProcessor.refillReadBuffer(AbstractAjpProcessor.java:576)
        at org.apache.coyote.ajp.AbstractAjpProcessor$SocketInputBuffer.doRead(AbstractAjpProcessor.java:1027)
        at org.apache.coyote.Request.doRead(Request.java:422)
        at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:290)
        at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:429)
        at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:315)
        at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:200)
        at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:976)
        at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:886)
        at java.io.InputStream.read(Unknown Source)
        at org.apache.commons.fileupload.util.Streams.copy(Streams.java:96)
        at org.apache.commons.fileupload.util.Streams.copy(Streams.java:66)
        at org.apache.jsp.fileupload_005fstreaming_jsp._jspService(fileupload_005fstreaming_jsp.java:125)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.ha.tcp.ReplicationValve.invoke(ReplicationValve.java:333)
        at org.apache.catalina.ha.session.JvmRouteBinderValve.invoke(JvmRouteBinderValve.java:219)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
        at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:200)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /fileupload_streaming.jsp at line 65

62: File uploadedFile = new File(saveDirectory, fileName);
63: FileOutputStream uploadedFileStream =
64: new FileOutputStream(uploadedFile);
65: Streams.copy(stream, uploadedFileStream, true);
66: }
67: }
68: }


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:460)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

java.net.SocketTimeoutException: Read timed out
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(Unknown Source)
java.net.SocketInputStream.read(Unknown Source)
org.apache.coyote.ajp.AjpProcessor.read(AjpProcessor.java:309)
org.apache.coyote.ajp.AjpProcessor.readMessage(AjpProcessor.java:364)
org.apache.coyote.ajp.AjpProcessor.receive(AjpProcessor.java:331)
org.apache.coyote.ajp.AbstractAjpProcessor.refillReadBuffer(AbstractAjpProcessor.java:576)
org.apache.coyote.ajp.AbstractAjpProcessor$SocketInputBuffer.doRead(AbstractAjpProcessor.java:1027)
org.apache.coyote.Request.doRead(Request.java:422)
org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:290)
org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:429)
org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:315)
org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:200)
org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:976)
org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:886)
java.io.InputStream.read(Unknown Source)
org.apache.commons.fileupload.util.Streams.copy(Streams.java:96)
org.apache.commons.fileupload.util.Streams.copy(Streams.java:66)
org.apache.jsp.fileupload_005fstreaming_jsp._jspService(fileupload_005fstreaming_jsp.java:125)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.23 logs.

Apache Tomcat/7.0.23

實際上傳的檔案大小如下:
-rw-r--r-- 1 tomcat tomcat 1073094361 2012-01-16 02:25 ppsds.pgf

目前我的web.xml中設定如下:
    <session-config>
        <session-timeout>10</session-timeout>
    </session-config>

目前我不確定是否跟session-timeout這個值有關係(10分鐘),不過整個1GB檔案上傳的時間大約有花半小時以上,您可以試試看調整這個參數再測試看看。

分享經驗 累積智慧
[WWW] [MSN]
羽小橘

十級學員

註冊時間: 2012-08-06 17:56:26
文章: 1
離線
andowson wrote:中文檔名上傳後變成亂碼或??的問題可以透過指定來源表單的編碼方式修正,另外上傳目錄也可以修改到Tomcat以外的目錄,例如C:\upload下(目錄不存在時也可以自動建立)
首先將來源表單的charset設為UTF-8
fileupload_streaming.html:
%>
[/code]


大大 我想請問一下 現在上傳檔案的姓名 根據檔案原本的名稱,也就是說 相同的名稱,會覆蓋同一個名稱,可以變成自己輸入檔案名稱嗎?

檔案說明的部分 有什麼作用嗎?

上傳之後的訊息 (是哪一段程式碼作用) 想再增加一個按鍵 返回 原頁面
 
討論區首頁 » 網頁程式設計 Web Development
前往: