Struts question reformatted !!!

Discussion in 'Java' started by Java_Forum, Sep 20, 2003.

  1. Java_Forum

    Java_Forum Guest

    <html>
    <font size="-1">
    hi,<BR>i am trying to do a simple thing without success!!!<BR>in my
    web application (designed under the struts framework), i have a logon action
    which check the username and password of a user, if it's ok i create and
    store an object User with a session scope.<BR>i have a another item at my
    menu wich enable a user to display his information (stored in the user
    object), here is the code. theres is 3 files<BR>EditmonCompteAction wich
    display the user information.<BR>User bean wich store information about the
    user.<BR>MoncompteForm is the bean form used in the mapping-action.<BR>and
    finally of course the
    struts-config.xml<BR><BR><pre><BR>EDITMONCOMPTEACTION<BR>*******************
    *<BR><b>public</b> <b>class</b> EditMonCompteAction <b>extends</b> Action
    {<BR><BR> <b>public</b> ActionForward execute(ActionMapping
    mapping,ActionForm form,HttpServletRequest request,HttpServletResponse
    response)<b>throws</b> Exception { <BR> <BR> <font
    color="#aa0000"><i>//Recupere l'utilisateur 'user' en cours</font></i><BR>
    User user = (User)
    (request.getSession()).getAttribute(Globals.USER_KEY);<BR> <b>if</b> (user
    == null)<BR> <b>return</b> mapping.findForward(<font
    color="#000099">"logon"</font>);<BR> <BR> <font
    color="#aa0000"><i>//Creation du form bean "moncompteForm" s'il n'existe
    pas</font></i><BR> <b>if</b> (form==null) {<BR> <font
    color="#aa0000"><i>//Creation du from-bean</font></i><BR> form =
    <b>new</b> MoncompteForm();<BR> <font color="#aa0000"><i>//Ajout a la
    requets ou session selon l'attribut "scope" de
    <action-mapping></font></i><BR> <b>if</b> (<font
    color="#000099">"request"</font>.equals(mapping.getScope()))<BR>
    request.setAttribute(mapping.getAttribute(),form);<BR> <b>else</b><BR>
    request.getSession().setAttribute(mapping.getAttribute(),form);<BR> }<BR>
    <BR> <font color="#aa0000"><i>//Copie de user vers form</font></i><BR>
    MoncompteForm moncompteForm = (MoncompteForm) form;<BR>
    PropertyUtils.copyProperties(moncompteForm, user);<BR> <BR> <font
    color="#aa0000"><i>//Attache un synchroniser token pour eviter le double
    posting</font></i><BR> saveToken(request);<BR> <BR> <font
    color="#aa0000"><i>//Renvoie vers moncompte</font></i><BR> <b>return</b>
    mapping.findForward(<font color="#000099">"moncompte"</font>); <BR> }
    <BR>}<BR></pre><BR>STRUTS-CONFIG.XML<BR>*****************<BR><pre><BR>....<B
    R><!-- ========== Global Forward Definitions
    ============================== --><BR> <global-forwards><BR>
    <forward name=<font color="#000099">"index"</font> path=<font
    color="#000099">"/index.jsp"</font>/><BR> <forward name=<font
    color="#000099">"logon"</font> path=<font
    color="#000099">"/logon.jsp"</font>/><BR> <forward name=<font
    color="#000099">"acceuilUser"</font> path=<font
    color="#000099">"/acceuilUser.jsp"</font>/><BR> <forward name=<font
    color="#000099">"moncompte"</font> path=<font
    color="#000099">"/moncompte.jsp"</font>/><BR>
    </global-forwards><BR>......<BR><!-- process an edit
    moncompte --><BR> <action path=<font
    color="#000099">"/editMonCompte"</font><BR> type=<font
    color="#000099">"eshop.actions.EditMonCompteAction"</font><BR>
    attribute=<font color="#000099">"moncompteForm"</font><BR>
    scope=<font color="#000099">"request"</font><BR> validate=<font
    color="#000099">"false"</font>/>
    <BR>......<BR></pre><BR>MONCOMPTEFORM<BR>*************<BR><pre><BR><b>public
    </b> <b>class</b> MoncompteForm <b>extends</b> ValidatorForm{<BR>....<BR>
    <b>private</b> String nom;<BR> <b>private</b> String prenom;<BR>
    <b>private</b> String password;<BR>....<BR> <b>public</b> <b>void</b>
    setNom(String nom) {<b>this</b>.nom=nom;}<BR> <b>public</b> <b>void</b>
    setPassword(String password) {<b>this</b>.password = password;}<BR>
    <b>public</b> <b>void</b> setPrenom(String prenom)
    {<b>this</b>.prenom=prenom;}<BR>....<BR> <b>public</b> String getNom()
    {System.out.println(<font color="#000099">"entr?e dans
    MonCOmpteForm.getNom"</font>);<b>return</b> nom;}<BR> <b>public</b> String
    getPassword(){<b>return</b> password;}<BR> <b>public</b> String getPrenom()
    {<b>return</b>
    prenom;}<BR>}<BR></pre><BR><BR>USER<BR>****<BR><pre><BR><b>public</b>
    <b>class</b> User {<BR>...<BR> <b>private</b> String nom;<BR> <b>private</b>
    String prenom;<BR> <b>private</b> String password;<BR>...<BR> <b>public</b>
    <b>void</b> setNom(String nom) {<b>this</b>.nom=nom; <BR> <b>public</b>
    <b>void</b> setPassword(String password) {<b>this</b>.password =
    password;}<BR> <b>public</b> <b>void</b> setPrenom(String prenom)
    {<b>this</b>.prenom=prenom;}<BR>....<BR>ublic String getNom() {<b>return</b>
    nom;}<BR> <b>public</b> String getPassword(){<b>return</b> password;}<BR>
    <b>public</b> String getPrenom() {<b>return</b>
    prenom;}<BR>}<BR></pre><BR>when the editMonCompte.execute() methode is
    performed, i have display the content of the form, and its property
    reflected those of the object USER, but nothing is displayed in the
    moncompte.jsp, which use ofcourse the struts html taglib (html:text,
    html:submit....)<BR><BR>i don't understand what's wrong with my
    code<BR>thanks for your help.
    </html>
    Java_Forum, Sep 20, 2003
    #1
    1. Advertising

  2. Java_Forum wrote:

    <snipped all the html>

    Please don't post HTML to a newsgroup.

    --
    mvg,
    Christophe Vanfleteren
    Christophe Vanfleteren, Sep 20, 2003
    #2
    1. Advertising

  3. Java_Forum

    James Guest

    Hello,

    a few things, I believe this is unnecessary:

    //Creation du form bean "moncompteForm" s'il n'existe pas
    if (form==null) {
    //Creation du from-bean
    form = new MoncompteForm();
    //Ajout a la requets ou session selon l'attribut "scope" de
    <action-mapping>
    if ("request".equals(mapping.getScope()))
    request.setAttribute(mapping.getAttribute(),form);
    else
    request.getSession().setAttribute(mapping.getAttribute(),form);
    }

    as long as your struts-config is set up properly, struts should
    automatically create a form bean for you and place it in the
    appropriate scope..

    however I don't think your action-mapping is correct.. it should be:

    <action path="/editMonCompte"
    type="eshop.actions.EditMonCompteAction"
    name="moncompteForm"
    scope="request"
    validate="false"/>

    I believe you used 'attribute' instead of 'name'.. check out
    strutsconsole (http://jamesholmes.com/struts/) it will validate your
    struts-config file for you..

    give that a try and see what happens..

    james

    "Java_Forum" <> wrote in message news:<bkhklq$30g$>...
    > <html>
    > <font size="-1">
    > hi,<BR>i am trying to do a simple thing without success!!!<BR>in my
    > web application (designed under the struts framework), i have a logon action
    > which check the username and password of a user, if it's ok i create and
    > store an object User with a session scope.<BR>i have a another item at my
    > menu wich enable a user to display his information (stored in the user
    > object), here is the code. theres is 3 files<BR>EditmonCompteAction wich
    > display the user information.<BR>User bean wich store information about the
    > user.<BR>MoncompteForm is the bean form used in the mapping-action.<BR>and
    > finally of course the
    > struts-config.xml<BR><BR><pre><BR>EDITMONCOMPTEACTION<BR>*******************
    > *<BR><b>public</b> <b>class</b> EditMonCompteAction <b>extends</b> Action
    > {<BR><BR> <b>public</b> ActionForward execute(ActionMapping
    > mapping,ActionForm form,HttpServletRequest request,HttpServletResponse
    > response)<b>throws</b> Exception { <BR> <BR> <font
    > color="#aa0000"><i>//Recupere l'utilisateur 'user' en cours</font></i><BR>
    > User user = (User)
    > (request.getSession()).getAttribute(Globals.USER_KEY);<BR> <b>if</b> (user
    > == null)<BR> <b>return</b> mapping.findForward(<font
    > color="#000099">"logon"</font>);<BR> <BR> <font
    > color="#aa0000"><i>//Creation du form bean "moncompteForm" s'il n'existe
    > pas</font></i><BR> <b>if</b> (form==null) {<BR> <font
    > color="#aa0000"><i>//Creation du from-bean</font></i><BR> form =
    > <b>new</b> MoncompteForm();<BR> <font color="#aa0000"><i>//Ajout a la
    > requets ou session selon l'attribut "scope" de
    > <action-mapping></font></i><BR> <b>if</b> (<font
    > color="#000099">"request"</font>.equals(mapping.getScope()))<BR>
    > request.setAttribute(mapping.getAttribute(),form);<BR> <b>else</b><BR>
    > request.getSession().setAttribute(mapping.getAttribute(),form);<BR> }<BR>
    > <BR> <font color="#aa0000"><i>//Copie de user vers form</font></i><BR>
    > MoncompteForm moncompteForm = (MoncompteForm) form;<BR>
    > PropertyUtils.copyProperties(moncompteForm, user);<BR> <BR> <font
    > color="#aa0000"><i>//Attache un synchroniser token pour eviter le double
    > posting</font></i><BR> saveToken(request);<BR> <BR> <font
    > color="#aa0000"><i>//Renvoie vers moncompte</font></i><BR> <b>return</b>
    > mapping.findForward(<font color="#000099">"moncompte"</font>); <BR> }
    > <BR>}<BR></pre><BR>STRUTS-CONFIG.XML<BR>*****************<BR><pre><BR>....<B
    > R><!-- ========== Global Forward Definitions
    > ============================== --><BR> <global-forwards><BR>
    > <forward name=<font color="#000099">"index"</font> path=<font
    > color="#000099">"/index.jsp"</font>/><BR> <forward name=<font
    > color="#000099">"logon"</font> path=<font
    > color="#000099">"/logon.jsp"</font>/><BR> <forward name=<font
    > color="#000099">"acceuilUser"</font> path=<font
    > color="#000099">"/acceuilUser.jsp"</font>/><BR> <forward name=<font
    > color="#000099">"moncompte"</font> path=<font
    > color="#000099">"/moncompte.jsp"</font>/><BR>
    > </global-forwards><BR>......<BR><!-- process an edit
    > moncompte --><BR> <action path=<font
    > color="#000099">"/editMonCompte"</font><BR> type=<font
    > color="#000099">"eshop.actions.EditMonCompteAction"</font><BR>
    > attribute=<font color="#000099">"moncompteForm"</font><BR>
    > scope=<font color="#000099">"request"</font><BR> validate=<font
    > color="#000099">"false"</font>/>
    > <BR>......<BR></pre><BR>MONCOMPTEFORM<BR>*************<BR><pre><BR><b>public
    > </b> <b>class</b> MoncompteForm <b>extends</b> ValidatorForm{<BR>....<BR>
    > <b>private</b> String nom;<BR> <b>private</b> String prenom;<BR>
    > <b>private</b> String password;<BR>....<BR> <b>public</b> <b>void</b>
    > setNom(String nom) {<b>this</b>.nom=nom;}<BR> <b>public</b> <b>void</b>
    > setPassword(String password) {<b>this</b>.password = password;}<BR>
    > <b>public</b> <b>void</b> setPrenom(String prenom)
    > {<b>this</b>.prenom=prenom;}<BR>....<BR> <b>public</b> String getNom()
    > {System.out.println(<font color="#000099">"entr?e dans
    > MonCOmpteForm.getNom"</font>);<b>return</b> nom;}<BR> <b>public</b> String
    > getPassword(){<b>return</b> password;}<BR> <b>public</b> String getPrenom()
    > {<b>return</b>
    > prenom;}<BR>}<BR></pre><BR><BR>USER<BR>****<BR><pre><BR><b>public</b>
    > <b>class</b> User {<BR>...<BR> <b>private</b> String nom;<BR> <b>private</b>
    > String prenom;<BR> <b>private</b> String password;<BR>...<BR> <b>public</b>
    > <b>void</b> setNom(String nom) {<b>this</b>.nom=nom; <BR> <b>public</b>
    > <b>void</b> setPassword(String password) {<b>this</b>.password =
    > password;}<BR> <b>public</b> <b>void</b> setPrenom(String prenom)
    > {<b>this</b>.prenom=prenom;}<BR>....<BR>ublic String getNom() {<b>return</b>
    > nom;}<BR> <b>public</b> String getPassword(){<b>return</b> password;}<BR>
    > <b>public</b> String getPrenom() {<b>return</b>
    > prenom;}<BR>}<BR></pre><BR>when the editMonCompte.execute() methode is
    > performed, i have display the content of the form, and its property
    > reflected those of the object USER, but nothing is displayed in the
    > moncompte.jsp, which use ofcourse the struts html taglib (html:text,
    > html:submit....)<BR><BR>i don't understand what's wrong with my
    > code<BR>thanks for your help.
    > </html>
    James, Sep 22, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Katie Wright
    Replies:
    8
    Views:
    4,238
    Andrea Desole
    Jan 7, 2005
  2. Jason Us
    Replies:
    0
    Views:
    984
    Jason Us
    Oct 4, 2003
  3. Ilkka Huotari

    W3C Specs reformatted

    Ilkka Huotari, May 15, 2004, in forum: HTML
    Replies:
    7
    Views:
    662
    B r ia n
    May 15, 2004
  4. Its Just the Devil

    X-Tract: Create a reformatted XLM file...

    Its Just the Devil, Nov 7, 2003, in forum: XML
    Replies:
    0
    Views:
    444
    Its Just the Devil
    Nov 7, 2003
  5. AnnMarie
    Replies:
    8
    Views:
    430
    kaeli
    Nov 21, 2003
Loading...

Share This Page