Descreva as etapas para referência.
Preparação:
Você precisa colocar os pacotes IO do Jakarta Commons FileUpload e Jakarta Commons na lib.
Minha bolsa aqui é:
Commons-FileUpload-1.1.1.jar
Commons-io-1.3.2.Jar
Em seguida, configure multipartresolver em spring-servlet.xml. Se o upload não estiver configurado corretamente, será difícil de usar.
<bean id = "multipartresolver"> <propriedade name = "maxuploadSize"> <value> 100000 </value> </property> <propriedade name = "defaultEncoding"> <Value> utf-8 </value> </propriedade> </bean>
Em seguida é a página:
Preste atenção à redação do formulário e à redação dos componentes de upload de arquivos.
<Form Action = "UPLOUPPOSDETAILFILE.HTML" MECLOTE = "POST" ENCTYPE = "Multipart/Form-Data"> <div> <p> <ppan> <input id = "startDatetxt" name = "startDatetxt"/> </span> <belt> Data: <pan> (date = " Formato: mm/dd/yyyy, por exemplo: 01/01/2014) </span> </elatbul> </p> <p> <pange> <input id = "enddatetxt" name = "enddatettxt"/> </span> <bret> Data: <pan> (data " Formato: mm/dd/yyyy, por exemplo: 25/12/2014) </span> </etiqueta> </p> <p> <pan> <input type = "file" name = "uploadfilectl"/> </span> <bel> file: <flage> (cliques para escolher) </> </> </> type = "submeter" value = "submeter"/> </div> </morm>
Em seguida, escreva o código de processamento no controlador, preste atenção à correspondência entre os parâmetros e o controle da página:
@RequestMapping (value = "/uploadPosDetailfile") public String UPLOPLOPOSDETAILFILE (@RequestParam ("startDatetxt") String StartDatetxt, @ReQuestParam ("enddatetTxt") string enddatetxt,@requestParam ("uplarloverfiltrl") multiplartFile ") resposta) {tente {System.out.println ("@@@@@@@@@@@@ 1.STARTDATETXT ="+startDatetxt); System.out.println ("@@@@@@@@@.enddatetTxt ="+enddatetxt); System.out.println ("@@@@@@@@@@@@@@5,5,@@@@@@@@@@@@@@@@@@@@@@@@@@(@@@@@@@@@@(@@@@@@@(@@@@@@@@@@@@@@@@@@@@@@@@ 1.startDatetTxt =”+startDatetxt); o nome do arquivo do arquivo carregado if (file.isEmpty () == false) {inputStream is = file.getInputStream (); inputStreamReader isr = new inputStreamReader (IS); BufferErader Br = new BufferReader (ISR); String s; while ((s = Br.readLine ())! = Null) {System.out.println (s);} Br.Close (); isr.close (); is.close (); is.close ();} return {e.printStackTrace (); logger.error (e); request.setAttribute ("error", e.getClass ()); request.setAttribute ("Razão", e.getMessage ()); sTackTraceElement [] arr = e.gettacktrace (); request.settribute ("StackStaceElements";