Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP, Struts, Bean Help

 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well,
I have a struts development using the tomcat server. I have a JSP, logon.jsp and I could not exactly understand in general what these lines are doing...
<html:form action="/logon" focus="username"
onsubmit="return validateLogonForm(this);">
<table border="0" width="100%">
<tr>
<th align="right">
<bean:message key="prompt.username"/>:
</th>
<td align="left">
<html:text property="username" size="16" maxlength="18"/>
</td>
</tr>
especially something like this <bean:message key="prompt.username"/>:
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Struts forum.
bear
 
veronique alvaro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
<bean:message key="prompt.username"/>
It means that the jsp page is looking in the ApplicationResources.properties file (you can find it under the WEB-INF/src directory) the message corresponding to the key : prompt.username. You could have something like this in the ApplicationResources.properties file :
prompt.username = Enter Username :
So you can change the message, without changing the code in the jsp page as you just call the key in it.
When you run the application you have on the jsp page :
<table border="0" width="100%">
<tr>
<th align="right">
Enter Username :
</th>
<td align="left">
</td>
</tr>
 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great that makes a lot of sense. But, what is going on here.
<html:form action="/logon" focus="username"
onsubmit="return validateLogonForm(this);">
<table border="0" width="100%">
 
veronique alvaro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you enter a username and submit it from the form, you call the action /logon from the struts-config.xml that could look like this:

This action is mapped with a bean named "logonForm" that you should find also in struts-config.xml described like this

The LogonAction (which extends Action) validates the username.
If the username is ok, you return (mapping.findForward("success"));
If the username is not ok, you return (mapping.findForward("failure"));
Going back to the Strut-config.xml, you can put for exemple in the global-forwards, the mapping for "success"
<forward name="success" path="/mainMenu.jsp"/>
If the user has the right username, it goes to mainMenu.jsp
Same for "failure" : you can redirect him for example back to the logon.jsp
<forward name="failure" path="/logon.jsp"/>
Hope it's clear !!!
V�ronique
 
sandy gupta
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best approach to learning struts is not to jump into the examples, but by reading about it. A lot of nice documentation is avl at : http://www.apache.org
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic