Javatpoint Logo

91-9990449935

 0120-4256464

Example to create struts 2 application in MyEclipse

Here, we are going to create the struts 2 application using myeclipse ide. We don't need to care about the jar files because MyEclipse provides these jar files.

You need to follow these steps to create struts 2 application.

  1. Create a web project
  2. Add struts 2 capabilities
  3. Create input page (index.jsp)
  4. Create the action class (Product.java)
  5. Map the request with the action in (struts.xml) file and define the view components
  6. Create view components (welcome.jsp)
  7. start server and deploy the project

1) Create a web project

To create web project, click on the file menu - new - project - web project - write the project name e.g. firststruts - finish.

2) Add struts 2 capabilities

To add struts 2 capabilities, select you project - click on the myeclipse menu - add project capabilities - add struts capabilities.

struts 2 with myeclipse ide

Select the 2.1 and /* as the url pattern - finish.

3) Create input page (index.jsp)

It uses struts core tags to create a form with fields.

index.jsp

4) Create the action class (Product.java)

It is the simple action class containing properties with setters and getters. It contains the execute method also for defining the business logic.

Product.java

5) Map the request in (struts.xml) file and define the view components

This xml file registers the action and view components.

struts.xml

6) Create view components (welcome.jsp)

This jsp page displays the information set in the action object.

welcome.jsp

7) start server and deploy the project

To start the server and deploy the project, right click on your project - Run As - MyEclipse server application.