解决问题:the request was rejected because no multipart boundary was found(亲测)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/smd2575624555/article/details/87876660

SpringMVC遇到的问题,表单提交报错,去掉content-type就好了

展开阅读全文

the request was rejected because no multipart boundary was found

05-19

upload.jsp rnrn<%@ page language="java" contentType="text/html; charset=gbk" rn pageEncoding="gbk"%> rn rn rn rn rn Insert title here rn rn rn rnrn rn rn rnrn rn rnrnUploadFile.java rnrnpublic class UploadFile extends HttpServlet rnrn protected void processRequest(HttpServletRequest request, rn HttpServletResponse response, String method) rn throws ServletException, IOException rn rn final long MAX_SIZE = 3 * 1024 * 1024; rnrnfinal String[] allowedExt = new String[] "jpg","gif" ; rnresponse.setContentType("text/html;charset=gbk"); rnrnresponse.setCharacterEncoding("gbk"); rnrnrnDiskFileItemFactory dfif = new DiskFileItemFactory(); rndfif.setSizeThreshold(4096); rndfif.setRepository(new File(request.getRealPath("/") rn+ "ImagesUploadTemp")); rnrnrnServletFileUpload sfu = new ServletFileUpload(dfif); rnrnsfu.setSizeMax(MAX_SIZE); rnrnPrintWriter out = response.getWriter(); rnrnList fileList = null; rntry rnfileList = sfu.parseRequest(request); rn catch (FileUploadException e) rnif (e instanceof SizeLimitExceededException) rnout.println("请选择小于等于:" + MAX_SIZE + "的文件 "); rnout.println(" 返回 "); rnreturn; rn rne.printStackTrace(); rn rnrnif (fileList == null || fileList.size() == 0) rnout.println("11"); rnout.println(" 返回 "); rnreturn; rn rnIterator fileItr = fileList.iterator(); rnrnwhile (fileItr.hasNext()) rnFileItem fileItem = null; rnString path = null; rnlong size = 0; rnrnfileItem = (FileItem) fileItr.next(); rnif (fileItem == null || fileItem.isFormField()) rncontinue; rn rnpath = fileItem.getName(); rnsize = fileItem.getSize(); rnif ("".equals(path) || size == 0) rnout.println("你选择的文件不正确 "); rnout.println(" 返回 "); rnreturn; rn rnString t_name = path.substring(path.lastIndexOf("\\") + 1); rnString t_ext = t_name.substring(t_name.lastIndexOf(".") + 1); rnint allowFlag = 0; rnint allowedExtCount = allowedExt.length; rnfor (; allowFlag < allowedExtCount; allowFlag++) rnif (allowedExt[allowFlag].equals(t_ext)) rnbreak; rn rnif (allowFlag == allowedExtCount) rnout.println("支撑的文件格式 "); rnfor (allowFlag = 0; allowFlag < allowedExtCount; allowFlag++) rnout.println("*." + allowedExt[allowFlag] rn + " "); rn out.println(" 返回 "); rnreturn; rn rnlong now = System.currentTimeMillis(); rnString prefix = String.valueOf(now); rnString u_name = request.getRealPath("/") + "ImagesUploaded/" rn+ prefix + "." + t_ext; rntry rnrnfileItem.write(new File(u_name)); rnout.println("文件名称: " + prefix + "." + t_ext rn+ " 文件大小: " + size + " "); rnout.println(" 返回 "); rn catch (Exception e) rne.printStackTrace(); rn rnrnrn rn out.println("123"); rn out.close(); rn rn protected void doGet(HttpServletRequest request, HttpServletResponse response) rn throws ServletException, IOException rn //Get主函数调用processRequest,完成Get方法的参数接受,返回的过程 rn processRequest(request, response, "GET"); rn rn protected void doPost(HttpServletRequest request, HttpServletResponse response) rn throws ServletException, IOException rn //POST主函数调用processRequest,完成POST方法的参数接受,返回的过程 rn processRequest(request, response, "POST"); rn rn rn报的错误 rnorg.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found rnat org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl. (FileUploadBase.java:814) rnat org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:323) rnat org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:341) rnat org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126) rnat UploadFile.processRequest(UploadFile.java:47) rnat UploadFile.doPost(UploadFile.java:124) rnat javax.servlet.http.HttpServlet.service(HttpServlet.java:710) rnat javax.servlet.http.HttpServlet.service(HttpServlet.java:803) rnat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) rnat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) rnat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228) rnat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) rnat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) rnat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) rnat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) rnat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216) rnat org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) rnat org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634) rnat org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445) rnat java.lang.Thread.run(Unknown Source) rnrn我 就是 想把他 改成 ajax 的 不 知道 怎么 改 rn 论坛

没有更多推荐了,返回首页