Salut a tous,
Je suis débutant en Struts, et j'ai un phénomène qui se produit souvent, je ne sais pas d'ou il vient, quel que soit mon script (en gal, recuperation des valeurs d'un form).
Lorsque je valide un formulaire, j arrive sur ma page upload.do Vide !
J'imagine donc qu il n y a pas de mappage entre le upload.do et le upload.jsp dans mon struts-config, mais je ne vois pas ou est le souci.
Voici le code :
Mon FormBean :
Mon Action :
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 package julien; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.upload.FormFile; public class UploadActionForm extends ActionForm { protected FormFile fichier; public FormFile getFichier() { return fichier; } public void setFile(FormFile fichier) { this.fichier = fichier; } public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors erreurs = new ActionErrors(); return erreurs; } }
mon struts-config :
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 package julien; import java.io.IOException; import javax.servlet.ServletException; 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 UploadAction extends Action{ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { final FormFile myFile; String cible = new String("succes"); if ( form != null ) { UploadActionForm UAFile = (UploadActionForm)form; myFile = UAFile.getFichier(); } else cible = new String("echec"); return (mapping.findForward(cible)); } }
Code xml : 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 <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd"> <struts-config> <!-- ========== Form Bean Definitions =================================== --> <form-beans> <form-bean name="myUpload" type="julien.UploadActionForm"/> </form-beans> <action-mappings> <action path="/upload" type="julien.UploadAction" name="myUpload" scope="request" validate="false" input="upload.jsp"> <forward name="succes" path="upload.jsp" /> <forward name="echec" path="index.jsp" /> </action> </action-mappings> </struts-config>
mon jsp :
Donc, ma console ne retourne pas d'erreur, pourtant, mon apres soumission du form, mon action upload.do me retourne une page vide .
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 <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <html:html > <head> <html:base/> </head> <body bgcolor="white"> <html:errors/> <html:form action="/upload.do" method="post" enctype="multipart/form-data"> <html:file property="fichier"></html:file> <html:submit>validez</html:submit> </html:form> </body> </html:html>
Avez vous une idée ???
Partager