jsp页面上导入.xls文件报错的解决方法
在jsp页面上导入.xls文件有报错现象怎么办?我们要怎样才能更好的解决这一问题呢?那么接下来我们就跟爱站小编一起去看看jsp页面上导入.xls文件报错的解决方法。
在jsp页面上导入.xls文件,报错:
java.io.IOException: Posted content type isn't multipart/form-data
at com.oreilly.servlet.multipart.MultipartParser.
at com.oreilly.servlet.MultipartRequest.
at org.apache.jsp.dxt.sms.multi_005fsender.upload_jsp._jspService(upload_jsp.java:406)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at sdcncsi.ict.security.AclFilter.doFilter(AclFilter.java:78)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at sdcncsi.ict.web.RequestFilter.doFilter(RequestFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
不知道是什么原因?应该怎样来解决呢?
解决这个错误,需要在form表单里面加上加enctype=”multipart/form-data” 这个属性,不过表单请求传到另一个jsp或servlet里时,是不能用request.getParameter()来获取到各个表单元素的值的,如下:
pageEncoding="UTF-8"%>
String res="true";
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
String file=(String)request.getParameter("t_file_excel");
//System.out.println(file);
String accountid3=(String)request.getParameter("accountid3");
String saveDirectory = "";
//获取配置参数,文件类型,文件大小
/*String date = "";
SimpleDateFormat gs = new SimpleDateFormat("yyyyMMdd");
Date now = new Date();
date = gs.format(now);*/
FileFuns fileFuns = new FileFuns();
try {
//判断文件类型
String file_type=SysPara.getValue("dxt_sms_multi_sender_file_type");
if(!file.substring(file.lastIndexOf(".")+1).equals(file_type))
{
out.println("");
return;
}
//判断文件夹是否存在,不存在创建
String file_path = SysPara.getValue("dxt_sms_multi_sender_file_path");
file_path=file_path.replace("\\","//");
if (!fileFuns.getFileIsExists(file_path)) {
fileFuns.Createdir(file_path);
}
String file_size = SysPara.getValue("dxt_sms_multi_sender_file_size");
//文件上传后,保存在saveDirectory
saveDirectory = file_path;
RandomFileRenamePolicy rfrp = new RandomFileRenamePolicy();
MultipartRequest multi = null;
System.out.println("saveDirectory"+saveDirectory);
System.out.println("file_size"+file_size);
multi = new MultipartRequest(request, saveDirectory, Integer
.parseInt(file_size), "utf-8", rfrp);
System.out.println("222"+multi);
//输出反馈信息
Enumeration files = multi.getFileNames();
while (files.hasMoreElements()) {
String name = (String) files.nextElement();
File f = multi.getFile(name);
if (f != null) {
String fileName = multi.getFilesystemName(name);
saveDirectory+=fileName;
}
}
} catch (Exception eu) {
res="false";
eu.printStackTrace();
out.println("");
}
%>
上文就是小编介绍jsp页面上导入.xls文件报错的解决方法,经过爱站小编详细的介绍后相信你一定可以轻松学会,喜欢的朋友赶紧get起来吧!
上一篇:jsp web.xml文件的作用
下一篇:如何批量处理JDBC语句