Je travail en ce moment sur une application web ou j'ai besoin d'uploader un fichier excel sur le serveur afin de le lire avec POI (et ensuite le supprimer mais ça on verra plus tard)

Après avoir lu la fac et plusieurs sujet ici j'ai pris et adapté plusieurs script sans succès.

Quoi que je face l'application me retourne toujours :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
ATTENTION: Exception from exceptionCommand 'servlet-exception'
java.lang.NullPointerException
	at action.StrutsUploadAction.execute(StrutsUploadAction.java:30)
	at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
	at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
	at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
	at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
	at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
	at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
	at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	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:175)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	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:263)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Unknown Source)

Je vous mes ci joint mes fichiers pour que vous puissiez voir ce qui pourrait cloquer :

StrutsUploadAction
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package action;
 
 
import java.io.File;
import java.io.FileOutputStream;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
 
public class StrutsUploadAction extends Action
{
  public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{	
 
		//Traitement de l'upload
 
		@SuppressWarnings("unused")
		StrutsUploadForm monForm = (StrutsUploadForm) form;
 
		FormFile myFile = monForm.getFileName();
      String contentType = myFile.getContentType();
      //recuperer le nom du fichier
      String fileName = myFile.getFileName();
      int fileSize = myFile.getFileSize();
      byte[] fileData = myFile.getFileData();
      //ca permet de retourne le chemin où sera sauvegarder le fichier
      String filePath = getServlet().getServletContext().getRealPath("/") +"upload";
      // Sauvegarde du fichier dans le serveur 
      if(!fileName.equals("")){  
      	System.out.println("Serveur path:" +filePath);
      	//creer le fichier
      	File fileToCreate = new File(filePath, fileName);
      	//si le fichier n'existe pas, il faut le sauvegarder                     
      	if(!fileToCreate.exists()){
      		FileOutputStream fileOutStream = new FileOutputStream(fileToCreate);
      		fileOutStream.write(myFile.getFileData());
      		fileOutStream.flush();
      		fileOutStream.close();
      	}
      }
 
 
      return mapping.findForward("success");
  }
}

Struts-config

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
	<form-beans>
		<form-bean name="FileUpload" type="action.StrutsUploadForm" />
	</form-beans>
 
	<action-mappings>
 
		<action path="/FileUpload" type="action.StrutsUploadAction"
			name="FileUpload" scope="request" validate="true" input="/ajouteAnnee.jsp">
			<forward name="success" path="/index.jsp" />
		</action>

StrutsUploadForm
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package action;
 
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
 
 
public class StrutsUploadForm extends ActionForm
{
	private FormFile fileName;
 
	public FormFile getFileName() {
		return fileName;
	}
 
	public void setFileName(FormFile fileName) {
		this.fileName = fileName;
	}
 
 
}
la JSP

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
<form action="FileUpload.do">
<input type="file" name="fichier" /> 
<br /><br />
<html:submit>Envoyez</html:submit>
</form>
Pour la JSP je voudrais bien utilisez <html:file> mais il me retourne un jasper exeption ...

Merci de votre aide

edit : pour <html:file> c'est bon maintenant mais j'ai toujours la même erreur...