1

我得到这个例外:

ClientAbortException:  java.net.SocketException: Connection reset by peer: socket write error

在代码中的这一行之后:

resp.flushBuffer();

我尝试了很多解决方案,但没有结果。

这是代码(在调试模式下,我在flushbuffer之后捕获了异常)

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException {
     super.doGet(req, resp);
 }
 @SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException {

     // process only multipart requests
     if (ServletFileUpload.isMultipartContent(req)) {
         // Create a factory for disk-based file items
         FileItemFactory factory = new DiskFileItemFactory();
         // Create a new file upload handler
         ServletFileUpload upload = new ServletFileUpload(factory);
         HttpSession session = req.getSession();
         // Parse the request
         try { 

             List<FileItem> items = upload.parseRequest(req);
             for (FileItem item : items) {
                 // process only file upload - discard other form item types
                 if (item.isFormField()){

                     continue;

                 }
                 String fileName = item.getName();
                 // get only the file name not whole path
                 if (fileName != null) {

                     fileName = FilenameUtils. getName(fileName);
                    //add session id to filename instead of authorname
                     fileName = req.getSession().getId() + fileName;

                 }

                 //String uploadDDTDIR = FileUtil.getRequiredFolder(DTCConstants.DDT_FILE_LOCATION);
                 String uploadDDTDIR="D:\\resources\\folderfile\\";

                 File uploadedFile = new File(uploadDDTDIR, fileName);

                 item.write(uploadedFile);

                 resp.setStatus(HttpServletResponse.SC_CREATED);


                 LOGGER.debug("The DDT file was created successfully."+uploadedFile.getName());

                 session.setAttribute(DTCConstants.UPLOADED_DTT_FILE, uploadedFile.getName());

                 resp.flushBuffer();


             }
         } catch (Exception e) {
             resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                   "An error occurred while creating the file : " + e.getMessage());
             System.out.println("testXX file DDTFileuploadservice line 99");
             LOGGER.error("DDTFileUploadService--doPost()",e);
        }

这是 Eclipse 窗口中的错误:

16:39:48,367 ERROR [[ddtFileUploadServlet]] "Servlet.service()" pour la servlet ddtFileUploadServlet a g�n�r� une exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at com.renault.dtc.server.DDTFileUploadService.doPost(DDTFileUploadService.java:101)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
4

0 回答 0