<html>
 <body>

  <!-- http://127.0.0.1:8080/ -->
  <form action="http://java.csdn.net/" method="post" enctype="multipart/form-data">
   <table border="1" align="center" width="230px">
    <tr>
     <td>
      <input type="file" name="upLoad"/>
     </td>
    </tr>
    <tr>
     <td align="center">
      <input type="submit" value="上传" style="width: 35%" id="upSubmit"/>
     </td>
    </tr>
   </table>
  </form> </body>
</html>
在上传给自己的tomcat时,没有做处理,就算访问的是不存在的webapp,tomcat也会一直下载,而我的浏览器也是一直在上传的,只见内存占用快速上升上面代码中测试了请求路径是:http://java.csdn.net/ 也是会一直上传的,可是改为:http://www.baidu.com/ 就不会有此问题了(显示:此程序无法显示网页)
挺奇怪的,怎么有的上传有的又不会了??不知道大家有没有解决办法,或者从web服务器怎样终止此次请求?web服务服务器tomcatwebappJavaEE

解决方案 »

  1.   

    具体后台debug一下。莫非和路径有关?
      

  2.   

    这里也有该类似的提问:http://www.iteye.com/topic/1020537
      

  3.   

    该场景为:当上传文件不满足要求(服务器端检查:如文件超过大小限制,扩展名不正确等),服务器在等待文件上传完成之前立即返回,目的是终止浏览器继续上传。 但是在实际应用中,并不能按上述预想的场景实现,实际情况是:服务器在文件上传过程中关闭响应输出流立即返回,并不能终止浏览器上传,上传的连接依然被保持,浏览器表现为依然在上传文件。 Google后,有一篇帖子或多或少说明了这个问题:http://stackoverflow.com/questions/3107631/how-to-close-a-http-connection-from-the-httpservlet 写道
    ASK:I'm running a servlet in Tomcat 6.0.26. The servlet accepts file upload from the client by HTTP POST. I'd like to stop the file uploading from the HttpServlet side. I tried the following methods with no luck:1. close the request inputstream
    2. send error code HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE and flush response
    3. do 1 and 2 in a FilterI googled but found no direct answers. Please advise solutions.Thanks.
    Answer:This is not possible using the standard Servlet nor Commons FileUpload API's. Basically, to be able to abort the connection immediately, you should grab the underlying socket physically and close it. However, this socket is controlled by the webserver. See also this related question:How to explicitly terminate http connection from server with no response header.Little tests have however confirmed that Commons FileUpload doesn't buffer up the entire file in memory when its size exceeds the limit. It will read the input stream, but just ignore and throw away the read bytes (also the ones which are already read). So memory efficiency isn't necessarily the problem here.To fix the real problem, you'd basically like to validate the file size in the client side rather than the server side. This is possible with a Java Applet or a Flash Application. For example, respectivelyJumpLoaderandSWFUpload.
      
     测试过程发现,如果上传巨大的文件,服务端(commons-fileupload 实现)会抛出 FileUploadBase$SizeLimitExceededException ,并且服务端立即返回响应;但是浏览器显示仍在上传中(普通html file控件),如果放任其不管,会发现客户端内存不断攀升(并非浏览器进程),服务端内存也不断攀升,直至浏览器失去响应。(因此并非上述帖子中提到的:如果大小超限,服务端在抛出异常后,会将读取的数据丢弃,因为实际看来这些资源并没有被立即释放)。 再次询问有没有好的解决的办法?