How to troubleshoot importing an. xls file error problem on a JSP page _jsp programming

Source: Internet
Author: User
Tags date now
Import an. xls file on a JSP page with an error:
java.io.IOException:Posted content type isn ' t multipart/form-data
At Com.oreilly.servlet.multipart.multipartparser.<init> (multipartparser.java:166)
At Com.oreilly.servlet.multipartrequest.<init> (multipartrequest.java:222)
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)
don't know what the reason is? How should it be solved?
To resolve this error, you need to add the enctype= "Multipart/form-data" attribute to the form form, but you cannot use Request.getparameter () when the form request is passed to another JSP or servlet. To get the values of the individual form elements, as follows:
Copy Code code as follows:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "
pageencoding= "UTF-8"%>
<%@ page session= "false"%>
<%@ include file= "/common/taglibs.jsp"%>
<%@ include file= "/common/meta.jsp"%>
<%@ include file= "/common/js.jsp"%>
<%@ page import= "java.util.*"%>
<%@ page import= "Java.text.SimpleDateFormat"%>
<%@ page import= "Sdcncsi.ict.util.SysPara"%>
<% @page import= "java.io.*,java.util.*,sdcncsi.ict.base.attachment.*"%>
<%@ page import= "Sdcncsi.ict.util.RequestUtil"%>
<% @page import= "Com.oreilly.servlet.MultipartRequest"%>
<%
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 = "";
Get configuration parameters, file type, file size
/*string date = "";
SimpleDateFormat GS = new SimpleDateFormat ("YyyyMMdd");
Date now = new Date ();
Date = Gs.format (now);
Filefuns filefuns = new Filefuns ();
try {
Determining File Types
String file_type=syspara.getvalue ("Dxt_sms_multi_sender_file_type");
if (!file.substring (File.lastindexof (".") +1). Equals (File_type))
{
Out.println ("<script>");
Out.println (' Alert (' ERROR: File type Error! ');");
Out.println ("</script>");
Return
}
To determine if a folder exists, there is no creation
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");
File upload, save in 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);
Output feedback Information
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 ("<script>");
Out.println (' Alert (' ERROR: File size exceeds limit! ');");
Out.println ("</script>");
}
%>
<script type= "Text/javascript" >
function Myunload () {
Window.opener.callback_getPageData_table_list (1);
}
</script>
<base target= "_self" >
<body onunload= "Myunload ()" >
<a id= "Reload" href= ' style= "Display:none" ></a>
</body>
<script>
var res= ' <%=res%> ';
if (res== ' true ')
{
Sys_ajaxpost ("/dxt/multi_sender.do?method=importmulti_sender&accountid=<%=accountid3%>&excelpath =<%=savedirectory%> "," ", Function (msg) {
if (msg.result==true) {
Location.href= "${ctx}/dxt/sms/multi_sender/multi_sender.jsp?result=true";
}else{
Location.href= "${ctx}/dxt/sms/multi_sender/multi_sender.jsp?result=false";
}
});
}
</script>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.