Import the. xls file on the jsppage. the following error occurs:
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)
I don't know why? How can this problem be solved?
To solve this problem, you must add the "enctype =" multipart/form-data "attribute in the form. However, when a form request is sent to another jsp or servlet, the request cannot be used. getParameter () to get the values of each form element, as follows:
Copy codeThe Code is 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 = "";
// Obtain the configuration parameters, file type, and file size.
/* String date = "";
SimpleDateFormat gs = new SimpleDateFormat ("yyyyMMdd ");
Date now = new Date ();
Date = gs. format (now );*/
FileFuns fileFuns = new FileFuns ();
Try {
// Determine the file type
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;
}
// Determine whether a folder exists and does not exist
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 ");
// After the file is uploaded, it is saved 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
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: the file size exceeds the limit! ');");
Out. println ("</script> ");
}
%>
<Head>
<Script type = "text/javascript">
Function myunload (){
Window. opener. callback_getPageData_table_list (1 );
}
</Script>
<Base target = "_ self">
</Head>
<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>