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.
- Create a web project
- Add struts 2 capabilities
- Create input page (index.jsp)
- Create the action class (Product.java)
- Map the request with the action in (struts.xml) file and define the view components
- Create view components (welcome.jsp)
- 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.
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.