我尝试在JSP中添加注释以用于上传文件,而不是使用Servlet,以便我可以仅处理一个文件JSP中上传的文件。我遇到了一些问题,希望能得到您的建议。我非常感谢你 我在web.xml中添加了多部分配置:
<servlet>
<servlet-name>uploadfile</servlet-name>
<jsp-file>/UploadFile.jsp</jsp-file>
<multipart-config>
<location>/tmp</location>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
</servlet>
<servlet-mapping>
<servlet-name>uploadfile</servlet-name>
<url-pattern>/UploadFile.jsp</url-pattern>
</servlet-mapping>
但是当我运行UploadFile.jsp时,我收到了IOExeption
java.io.IOException: The temporary upload location [D:\Java\WorkSpace(ThuNghiem2)\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\Buoi32\tmp] is not valid
org.apache.catalina.connector.Request.parseParts(Request.java:2821)
org.apache.catalina.connector.Request.getParts(Request.java:2754)
org.apache.catalina.connector.Request.getPart(Request.java:2917)
org.apache.catalina.connector.RequestFacade.getPart(RequestFacade.java:1105)
org.apache.jsp.UploadFile_jsp._jspService(UploadFile_jsp.java:235)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
UploadFile.JSP中的内容是什么
<form method="POST" action="" enctype="multipart/form-data">
<input type="file" name="image" multiple /> //I just add 1 image per time for experiment
<button type="submit" name="uploadclick">Upload</button>
</form>
<%
if(request.getPart("image")!=null){
Part p = request.getPart("image");
///// do ST
}else{
///// Do ST
}
%>