leejeok

The Remarkable Everyday

Archive for May 8th, 2008

Struts for navigation between JSP pages

Posted by leejeok on May 8, 2008

I will use the ActionClass to navigate the client to the proper JSP pages. The ActionClass will decide which JSP page to be display on the browser.

By having the configurations file, I will specified the pages within here.

 

<action

          path= “/somerequest”

          type=”com.somepackage.someAction”

          scope=”request”

          name=”someForm”

          validate=”true”

          input=”somePage.jsp”>

          <forward name=”Success” path=”/successPage.jsp” redirect=”true”/>

             <forward name=”Failure” path=”/errorPage.jsp” redirect=”true”/>

</action>

 If you are building a login page and would like to redirect client to the menu page after success login, perhaps your configuration file would look similar like this:

<action

input=”/login.jsp”

name=”loginForm”

path=”/myapplication”

scope=”request”

type=”com.myapplication.struts.loginAction”>

      <forward name=”success” path=”/mainmenu.jsp”/>       

</action>

Here, I included with the program which require client to enter some input before allow to proceed to the next page. Click HERE

Posted in Struts | Leave a Comment »

Struts for validation field in JSP

Posted by leejeok on May 8, 2008

One of the reasons to use Struts is the capabilities to validate the entries of data which pass from the user input. The validation process will be code within the ActionClass and pass it back to the ActionForm class. 

Generally, ActionForm:
1. encapsulate the data from the View to be transafer to the Controller.
2. having the getter and setter method to allow input to be mapped from the JSP.
3. having the validate() method which will perform the validation process.
3. represent as VIEW components within the MVC design pattern.
In other word, ActionForm Bean Populating the view, Provide Input to Action class, and Perform Validation.

Generally, the ActionClass:
1. Represent as the Controller components. Serve as the bridge to communicate between View and Model components.
2. Contain the execute() method which will interface with Model for business process and forward the control to View to display.

I have a sample of program which will only perform the validation process.  Click Here.

After processing the validation, the ActionClass will redirect to the proper page and this will be explain on the next blog.

Posted in Struts | Leave a Comment »