文件上传适用于IE,但不适用于Chrome和Mozilla

时间:2014-04-01 12:40:55

标签: jsp servlets file-upload

我正在尝试将文件从一个驱动器复制到另一个驱动器,就像我们在网页上一样。我正在使用jsp-servlet组合。为了复制文件,我使用了FileChannel。 这在Eclipse的内置浏览器和IE上工作得很好,但在Chrome或Mozilla上却没有。有什么建议??

的index.jsp

form action="Upload">
    <table>
        <tr>
            <td><input type ="file" name="file"></td>
            <td><input type="submit" name="submit" value="UPLOAD"></td>
        </tr>
    </table>
</form>

Upload.java

File f = new File(request.getParameter("file").toString());

        FileChannel ic = null;
        FileChannel oc = null;

        try
        {
            ic = new FileInputStream(request.getParameter("file").toString()).getChannel();
            oc = new FileOutputStream("e:\\"+f.getName()).getChannel();
            oc.transferFrom(ic, 0, ic.size());
        }
        finally
        {
            ic.close();
            oc.close();
        }

Eclipse上的控制台:

Apr 01, 2014 5:18:00 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [util.Upload] in context with path [/FileUpload] threw exception
java.lang.NullPointerException
    at util.Upload.doGet(Upload.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:550)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:380)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

0 个答案:

没有答案