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 :

Exception creating bean of class et débuts difficiles avec Struts


Sujet :

Struts 1 Java

  1. #1
    Membre du Club
    Inscrit en
    Juillet 2006
    Messages
    143
    Détails du profil
    Informations forums :
    Inscription : Juillet 2006
    Messages : 143
    Points : 69
    Points
    69
    Par défaut Exception creating bean of class et débuts difficiles avec Struts
    Salut à tous, après de nombreuses recherches et 2 jours passées à galérer avec struts, je vous demande un petit coup de main pour me lancer avec struts.

    Pour le moment j'essaie de faire un truc basique de chez basique, ouvrir un formulaire jsp avec identifiant et mot de passe - valider - nouvelle page affichant l'identifiant saisi.

    Je précise que le projet est un projet web crée sous eclipse, tous les plugins sont installés (aucune erreur d'import)

    Voici l'arborescence du projet :


    Voici le code :

    login.jsp
    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
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    	pageEncoding="ISO-8859-1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
     
    <%@ page language="java" import="java.util.*"  %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
     
    </head>
    <body>
    	<div id="top">
    		<h1>Bourse du transport</h1>
    	</div>
     
    	<div id="gauche"></div>
     
    		<div id="contenu">
    			<h1>Bienvenue. Veuillez vous identifier.</h1>
    			<div>
    				<html:form action="login.do" method="GET" focus="login">
    	        		Login : <html:text property="login" /><br />
    			        Password : <html:password property="password" /><br />
    				<html:submit property="submit" />
    				</html:form>
    			</div>
    		</div>
    </body>
    </html>
    LoginForm.java

    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
    package login;
     
    import org.apache.struts.action.ActionForm;
     
    public class LoginForm extends ActionForm {	
     
    	private String login; 
    	private String password;
     
    	public LoginForm() {
    		super();
    	}
     
    	public String getLogin() {
    		return login;
    	}
    	public void setLogin(String login) {
    		this.login = login;
    	}
    	public String getPassword() {
    		return password;
    	}
    	public void setPassword(String password) {
    		this.password = password;
    	}
    }
    LoginAction.java
    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
    package login;
     
    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;
     
    public class LoginAction extends Action {
    	public ActionForward execute(
    			ActionMapping mapping, ActionForm _form,
    			HttpServletRequest request, HttpServletResponse response
    	) throws Exception {
    		// On traite la requête cliente
    		LoginForm form = (LoginForm) _form;
    		System.out.println("Struts in action "
    				+ form.getLogin() + " - " + form.getPassword());
    		// On redirige vers la vue adaptée
    		return mapping.findForward("Accueil");
    	}
    }
    Struts-config.xml
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
              "http://struts.apache.org/dtds/struts-config_1_3.dtd">
    <struts-config>
     
    	<!-- ========== Form Bean Definitions ================================== -->
    	<form-beans>
    		<!-- Login ActionForm Bean -->
    		<form-bean name="LoginForm" type="login.LoginForm" />
    	</form-beans>
     
    	<!-- ========= Global Exception Definitions ============================ -->
    	<global-exceptions></global-exceptions>
     
    	<!-- ========== Global Forward Definitions ============================= -->
     
    	<global-forwards></global-forwards>
     
    	<!-- ========== Action Mapping Definitions ============================= -->
     
    	<action-mappings>
     
    		<!-- Login ActionForm Example ===================================== -->
    		<action path="/login"
                   	name="LoginForm"
    				type="login.LoginAction"
                    scope="request">
                    <forward name="Accueil" path="/Accueil.jsp" />               
            </action>
     
    	</action-mappings>
     
    	<!-- ========== Message Resources Definitions =========================== -->
     
     
     
    	<!-- ========== Plug Ins Configuration ================================== -->
     
     
    </struts-config>
    Web.xml (au cas où)
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4"
    	xmlns="http://java.sun.com/xml/ns/j2ee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    	<display-name>projetili</display-name>
    	<welcome-file-list>
    		<welcome-file>index.html</welcome-file>
    		<welcome-file>index.htm</welcome-file>
    		<welcome-file>index.jsp</welcome-file>
    		<welcome-file>default.html</welcome-file>
    		<welcome-file>default.htm</welcome-file>
    		<welcome-file>default.jsp</welcome-file>
    	</welcome-file-list>
     
    	<servlet>
    		<servlet-name>action</servlet-name>
    		<servlet-class>
    			org.apache.struts.action.ActionServlet
    		</servlet-class>
    		<init-param>
    			<param-name>config</param-name>
    			<param-value>/WEB-INF/struts-config.xml</param-value>
    		</init-param>
    		<init-param>
    			<param-name>debug</param-name>
    			<param-value>2</param-value>
    		</init-param>
    		<init-param>
    			<param-name>application</param-name>
    			<param-value>ApplicationResources</param-value>
    		</init-param>
    		<load-on-startup>2</load-on-startup>
    	</servlet>
     
    	<servlet-mapping>
            <servlet-name>action</servlet-name>
            <url-pattern>*.do</url-pattern>
        </servlet-mapping>
     
        <taglib>
            <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
        </taglib>
    </web-app>
    Accueil.jsp
    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
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Confirmation de connexion</title>
     
    <%@ page language="java" import="java.util.*"  %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
     
    </head>
    <body>
            <h1 align="center">Confirmation de connexion</H1>
     
            <div align="center">
    	        Bonjour <bean:write name="LoginForm" property="login" />
            </div>
     
        </body>
    </html>
    J'obtient l'erreur suivante :

    exception

    javax.servlet.ServletException: Exception creating bean of class login.LoginForm: {1}
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
    org.apache.jsp.jsp.login_jsp._jspService(login_jsp.java:101)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


    cause mère

    javax.servlet.jsp.JspException: Exception creating bean of class login.LoginForm: {1}
    org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:465)
    org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:432)
    org.apache.jsp.jsp.login_jsp._jspx_meth_html_form_0(login_jsp.java:119)
    org.apache.jsp.jsp.login_jsp._jspService(login_jsp.java:89)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


    toute aide serait la bienvenue - merci

  2. #2
    Membre expérimenté Avatar de willoi
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    1 355
    Détails du profil
    Informations personnelles :
    Âge : 51
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 355
    Points : 1 639
    Points
    1 639
    Par défaut
    dans ton jsp tu devrais plutot utiliser la method POST,

    <html:form action="login.do" method="POST" focus="login">

    mais bon je doute que ce soit qui provoque cette erreur ...

  3. #3
    zag
    zag est déconnecté
    Membre régulier

    Profil pro
    Inscrit en
    Mars 2005
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 58
    Points : 75
    Points
    75
    Par défaut
    Bonjour,

    comment accèdes tu à ta jsp, en mettant directement login.jsp dans l'url?

    Si tel est le cas, cela veut dire que tu ne passe par aucun controleur au prélable et que ton formulaire n'est pas créé, donc le tag html:form ne le trouve pas et te renvoi cette exception.

    Donc il te faut une action avec un forward vers login.jsp. Tu peux le faire dans LoginAction en effectuant un test pour choisir si tu forward sur login.jsp (à l'arrivée de l'utilisateur) ou vers accueil.jsp(une fois le formulaire validé) ou te créer une autre action spécifique.

    A toi de voir...

  4. #4
    Membre du Club
    Inscrit en
    Juillet 2006
    Messages
    143
    Détails du profil
    Informations forums :
    Inscription : Juillet 2006
    Messages : 143
    Points : 69
    Points
    69
    Par défaut
    Apparemment ca fonctionne

    j'ai rajouté les constructeurs dans les classes java et cette methode dans LoginForm.java

    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
    public ActionErrors validate(
    			ActionMapping mapping,
    			HttpServletRequest request) {
     
    		ActionErrors errors = new ActionErrors();
     
    		// Le login et mot de passe doivent être renseignés
    		if ((login.length() == 0))
    			errors.add("login", new ActionMessage("error.login.required"));
     
    		if ((password.length() == 0))
    			errors.add("password", new ActionMessage("error.password.required"));
     
    		return (errors);
     
    	}

  5. #5
    Nouveau Candidat au Club
    Inscrit en
    Mars 2010
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Mars 2010
    Messages : 1
    Points : 1
    Points
    1
    Par défaut
    Merci pour cette réponse
    c très claire

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 19/10/2008, 23h31
  2. Exception creating bean of class
    Par rashid120 dans le forum Struts 1
    Réponses: 3
    Dernier message: 15/02/2008, 15h42
  3. Exception creating bean - le retour
    Par devgru dans le forum Struts 1
    Réponses: 15
    Dernier message: 14/12/2007, 14h20
  4. ActionForm : Exception creating bean...
    Par am.adnane dans le forum Struts 1
    Réponses: 6
    Dernier message: 12/06/2007, 14h29
  5. [struts]Exception creating bean
    Par rafounette dans le forum Struts 1
    Réponses: 16
    Dernier message: 10/03/2006, 19h54

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