Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Struts question reformatted !!!

Reply
Thread Tools

Struts question reformatted !!!

 
 
Java_Forum
Guest
Posts: n/a
 
      09-20-2003

<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_K EY);<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.getAttri bute(),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>


 
Reply With Quote
 
 
 
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      09-20-2003
Java_Forum wrote:

<snipped all the html>

Please don't post HTML to a newsgroup.

--
mvg,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
 
James
Guest
Posts: n/a
 
      09-21-2003
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.getAttri bute(),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" <(E-Mail Removed)> wrote in message news:<bkhklq$30g$(E-Mail Removed)>...
> <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_K EY);<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.getAttri bute(),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>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I reformatted. Cd rom drives not reading now nevermore studio Computer Support 5 11-28-2007 02:11 AM
slow to boot up after reformatted my SATA harddisk (HDD) Ko Po Hui Computer Support 4 12-17-2005 10:20 PM
recover data from reformatted disk feedmecereal@hotmail.com Computer Support 5 05-12-2005 11:01 PM
W3C Specs reformatted Ilkka Huotari HTML 7 05-15-2004 08:51 PM
X-Tract: Create a reformatted XLM file... Its Just the Devil XML 0 11-07-2003 06:44 PM



Advertisments