IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Struts 1 Java Discussion :

Upload Struts impossible


Sujet :

Struts 1 Java

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    31
    Détails du profil
    Informations personnelles :
    Âge : 35
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 31
    Par défaut Upload Struts impossible
    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...

  2. #2
    Membre émérite
    Profil pro
    Développeur Back-End
    Inscrit en
    Avril 2003
    Messages
    782
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Back-End

    Informations forums :
    Inscription : Avril 2003
    Messages : 782
    Par défaut
    bonjour,

    c'est un problème de form

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <form action="FileUpload.do" ENCTYPE="multipart/form-data">
    <input type="file" name="fichier" /> 
    <br /><br />
    <html:submit>Envoyez</html:submit>
    </form>

Discussions similaires

  1. [Eclipse / Tomcat / Struts] Impossible d'afficher index.html
    Par scourt dans le forum Eclipse Java
    Réponses: 0
    Dernier message: 27/03/2015, 16h23
  2. probleme d'upload struts et postgres
    Par userist dans le forum Struts 1
    Réponses: 14
    Dernier message: 09/04/2010, 15h29
  3. [Upload] Chargement impossible
    Par marlou391 dans le forum Langage
    Réponses: 13
    Dernier message: 28/04/2009, 09h10
  4. [Upload] move_uploaded_file impossible mais erreur=0
    Par mathieugamin dans le forum Langage
    Réponses: 5
    Dernier message: 05/09/2007, 13h47
  5. [Struts][Oracle]Upload fichier word dans une base
    Par Maximil ian dans le forum Struts 1
    Réponses: 7
    Dernier message: 10/02/2004, 15h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo