我正在尝试将简单图像上传到服务器。除了图像数据,我还有一个参数,指定它属于谁。
客户端:
<form method="POST" action="../servlet" enctype="multipart/form-data" name="imgdata">
<input type="text" class="se" style="display:none;" name="se"/>
<div class="browser">
<label class="take">
<input type="file" name="ImagesFile" class="Propicselecter_file" id="Propicselecter_file" size="1" accept="image/*" id="imagetoupload" name="fname1"/>
<span>Browse</span>
</label>
</div>
<input type="submit" class="sub" value="Finish"/>
</form>
然后在服务器中我有:
response.setContentType("text/html");
String name = request.getParameter("se");
System.out.println(name);
MultipartRequest multipartRequest = new MultipartRequest(request, "C:/", 5000000, "ISO-8859-1", new DefaultFileRenamePolicy());
发送的图片完全保存在c:/name.extension
,但问题是我的名称参数为null
。
完整堆栈异常:
at org.apache.catalina.connector.Request.parseParts(Request.java:2733)
at org.apache.catalina.connector.Request.getParts(Request.java:2699)
at org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:1096)
at duck.reg.pack.stkbkimgup.doPost(stkbkimgup.java:28)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
我不知道自己做错了什么。