Thursday, June 27, 2013

Hello World Application using Struts 2.1


- Create a Java Project & Add Struts Capabilities to the project.

- Develop index.jsp as shown below, Ensure form action value will be used in struts.xml

- Ensure web.xml should be as shown below

- Define welcome.jsp with whatever you want to display.

- Develop a Customer.java POJO class as shown below, Ensure this should have a method called execute() , Struts framework will invoke execute() method internally.. This method can return any string value based on functional requirement.


- Modify struts.xml as shown below
  - Configure action element as shown below
  -  Add as many result elements as you want based on execute() method return values.. If execute() method returns "success" , "failure" depends on two conditions, then define two result elements as shown below.


- Run this application , Right click on project, Run As ->MyEclipse Server Application

- By default, it will launch index.jsp

- By clicking on 'Submit' button , this will invoke form action and navigate to based on execute() method return value.


No comments:

Post a Comment