gpt4 book ai didi

jsp - jsp文件上传问题

转载 作者:行者123 更新时间:2023-12-02 15:40:12 25 4
gpt4 key购买 nike

我必须上传一个文件,而我正在尝试运行显示消息

 org.apache.jasper.JasperException: Exception in JSP: /RootSipResource.jsp:33

30: out.println("Cookies" + request.getCookies());
31:
32: DiskFileUpload upload=new DiskFileUpload();
33: List items=upload.parseRequest(request);
34: Iterator it=items.iterator();
35: while(it.hasNext())
36: {


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

root cause

javax.servlet.ServletException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.RootSipResource_jsp._jspService(RootSipResource_jsp.java:577)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

root cause

org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:768)
org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:323)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:341)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:302)
org.apache.jsp.RootSipResource_jsp._jspService(RootSipResource_jsp.java:91)

在jsp页面中表单域设置为

<form name="frm" id="frmLoad" method="post" enctype="multipart/form-data">  

isMultipart 打印为 true(boolean isMultipart = FileUpload.isMultipartContent(request);)

       `out.println("Content Type ="+request.getContentType());` is printed as null

最佳答案

此异常表明method="post"enctype="multipart/form-data" <form> 中缺少元素。但由于它们显然存在,原因在别处。也许您正在嵌套表单,或者误解了结果,或者没有运行您认为正在运行的代码。

无论如何,应该避免在 JSP 文件中编写 Java 代码。使用一个小服务程序。您可以在此答案中找到具体示例:How to upload files to server using JSP/Servlet?

关于jsp - jsp文件上传问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8412482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com