|
|
|
| HOME | J2ME | Struts | AJAX | SOAP | SOA | MEDIA STREAMING | AXIS | | |
|
|
Struts for Beginners: Forms & Action FormsBack | Tutorial Home | Next Lets now explore the forms. Forms are the HTML elements where the user enters some values and submits the form and gets the results page. We will now create a login page to see how it works in struts. Struts comes with to tag libraries. You need to import these libraries into a JSP page. <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"
%> This works in Struts 1.3 version but for struts 1.2 and below The following code has to be inserted in web.xml <taglib> Then import the tag libraries in your code by inserting the following code into JSP page <%@ taglib uri="/tags/struts-html" prefix="html"%> Sample Form <html:form action="loginAction">
action property in <html:form> element the and is mapped in the struts-config.xml to repective action. The other elements like <html:text> and <html:password> are mapped to ActionForm Bean. These mappings have to be inserted into struts-config.xml. We will study these mappings as we create the requisite classes struts-config.xml <action path="/loginAction"
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"
%> ActionForm Action Form is the bean where all the parameters sent from the from are stored. To create an this bean your class should extend from ActionForm
Use reset() method to reset bean values.
Now that the parameters are received, Next validations have to be done for the request parameters. Struts provides a method validate(). All the requisite validations are done in this method and the errors are logged in an ActionErrors object. If there are no errors then the controller forwards the request to Action class defined in the struts-config. And if error is detected the loginForm.jsp is invoked with error messages displayed in place of <html:errors/> tag in the login form. In the below code the error handling is done using ActionErrors class ActionErrors errors = new ActionErrors(); When the error is detected ActionMessage object with error massage is added to ActionErrors object errors.add("userName", new ActionMessage("login.userName.error")); In case of Struts1.2 and below ActionError object is used instead of ActionMessage. ActionError class is deprecated in Struts 1.3
Back | Tutorial Home | Next site comments powered by Disqus |
|
| toolbar powered by Conduit |
|
| Copyright © 2009. All rights reserved | Terms and Conditions | About | Contact | Feed Back | |