报错信息如下,显示问题出在HttpFileUpload.java这个类的parseRequest()方法:
2009-09-04 08:52:13 错误 [apusic.web.dzzw./dzzw] 执行Servlet时发生错误。 java.lang.NullPointerException at org.apache.commons.fileupload.MultipartStream $ItemInputStream.makeAvailable(MultipartStream.java:967) at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read (MultipartStream.java:887) at java.io.InputStream.read(InputStream.java:85) at org.apache.commons.fileupload.util.Streams.copy(Streams.java:94) at org.apache.commons.fileupload.util.Streams.copy(Streams.java:64) at org.apache.commons.fileupload.MultipartStream.readBodyData (MultipartStream.java:593) at org.apache.commons.fileupload.MultipartStream.discardBodyData (MultipartStream.java:619) at org.apache.commons.fileupload.MultipartStream.skipPreamble (MultipartStream.java:638) at com.cnblogs.zxub.upload.HttpFileUpload.parseRequest (HttpFileUpload.java:212) at _jspx._bangong._oa._gonggao._program._gonggao_5finsert__jsp._jspService (bangong/oa/gonggao/program/gonggao_insert.jsp:29) at com.apusic.web.jsp.runtime.HttpJspPageImpl.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at com.apusic.web.container.ServletComponent.service(Unknown Source) at com.apusic.web.container.WebContainer.invoke(Unknown Source) at com.apusic.web.container.WebContainer.invoke(Unknown Source) at com.apusic.web.jsp.JspServlet.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at com.apusic.web.container.ServletComponent.service(Unknown Source) at com.apusic.web.container.WebContainer.invoke(Unknown Source) at com.apusic.web.container.WebContainer.processRequest(Unknown Source) at com.apusic.web.http.VirtualHost.processRequest(Unknown Source) at com.apusic.web.http.HttpServer.processRequest(Unknown Source) at com.apusic.web.http.HttpConnectionHandler.service(Unknown Source) at com.apusic.web.http.ConnectionHandler.processRequest(Unknown Source) at com.apusic.web.http.ConnectionHandler.processConnection(Unknown Source) at com.apusic.web.http.ConnectionHandler.run(Unknown Source) at com.apusic.util.ThreadPoolImpl$WorkerThread.run(Unknown Source)
当时由于不知道的原因,HttpFileUpload.java这个文件客户无法提供源码,没办法进行跟踪调试,定位具体出错的位置;
gonggao_insert.jsp页面部分代码如下:
String filename=""; String newfilename=""; String path="UploadFile/bangong/oa/gonggao"; DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(4096); factory.setRepository(new File(application.getRealPath("\\") + path)); HttpFileUpload upload = new HttpFileUpload(factory); upload.setAllowFileTypes(""); upload.setSizeMax(1000*1024*1024); List fileItems = upload.parseRequest(request); //异常提示在此报错(gonggao_insert.jsp:29) Iterator iter = fileItems.iterator(); while(iter.hasNext()){ FileItem fi=(FileItem)iter.next(); String fileName = fi.getName(); File tempFile = new File(fileName); fileName = tempFile.getName(); String newfileName=""; if(!"".equals(fileName)) { fileName=fileName.substring(fileName.lastIndexOf("\\")+1,fileName.length()); String Suffix=fileName.substring(fileName.lastIndexOf("."),fileName.length()); uuid.UUID uuid0=new uuid.UUID(); String ID=String.valueOf(uuid0); newfileName=ID+Suffix; newfilename+=newfileName+"@@"; filename+=fileName+"@@"; fi.write(new File(application.getRealPath("\\") + path, newfileName)); } }