Structs frame work is used to developed web based application. It simplifies the development of web based applications, By using structs we can develop only web based applications, We can't develop the standard alone applications.
We can use any of the following frameworks to develop the web based applications.
they are
1.) Structs
2.)Spring
3.)jsf
4.) Web work
5.) openSymposy
The required files to Develop struts application:
web container creates Actionservlet object where as FormBean class object, Action class object will be created by ActionServlet.
We can use any of the following frameworks to develop the web based applications.
they are
1.) Structs
2.)Spring
3.)jsf
4.) Web work
5.) openSymposy
The required files to Develop struts application:
- register.jsp
- success.jsp
- failure.jsp
- RegisterAction.java
- RegisterForm.java
- struts-html.tld
- web.xml
- struts-config.xml
Struts Flow / Struts Architecture
Web.xml entries will be read by web container of webserver or application server software. Struts configuration file entry is will be read by action servlet.
Web.xml entries will be read by web container of webserver or application server software. Struts configuration file entry is will be read by action servlet.
web container creates Actionservlet object where as FormBean class object, Action class object will be created by ActionServlet.
- In the above diagram Business Logic is kept in Action class ..so it is called as "MODEL".
- Execute method in Action class is fixed method.Earlier this method is given as perform(-,-,-,-)method .
- Perform(-,-,-,-) is the deprecated method of execute(-,-,-,-) method form Struts1.1 version onwards.
- Struts 1.0-> perform(-,-,-,-) method
- Struts 1.2,1.3 -> perform(-,-,-,-) (deprecated) , execute(-,-,-,-).
With respect to the above diagram:
1. End user submits the request from JSP form(register.jsp) to struts based web application.
2. Based on the configuration done in web.xml ActionServlet traps the request and takes the result.
3. ActionServlet uses struts configuration file entries to decide FormBean, Action class to be utilized to process the request.
4. ActionServlet creates or locates FormBean class object and writes received from data to FormBean class object.
5. ActionServlet creates or locates Action class object.
6. ActionServlet calls execute(-,-,-,-)method of Action class, Business logic of execute(-,-,-,-) mehtod executes and result will be generated.
7. ActionServlet takes the control from Action class.
8. ActionServlet uses Action forward configurations of struts configuration file to decide result JSP(result.jsp) page of Action class.
9. ActionServlet forwards the control to resultpage called result.jsp.
10. Presentation logic of result page executes(result.jsp) to formatt result goes to browser as response.
11. This formatted result goes to browser as response.
//Reading struts Configuration file.
Reading request data, creating or locating FormBean, Action class Objects are the responsibilities of ActionServlet.
X.jsp ----> Form
XForm ---> FormBean class
XAction ---> Action class
Ex:
register.jsp ---> Form
Register form ---> FormBean
Register Action ---> Action class
naming conventions are very useful to make sources of the application selfdescriptive.
//Any .xml can act as structs configuration file. there is no default struts configuration file name.
- If Business Logic is kept in Action class then it is called MODEL.
- If Action class contains logic to interact with other model components like EJB, SPRING WITH HIBERNATE applications then Action class is called helper to controller servlet called Action servlet.
Q: Which roll you prefer for Action class.
A: We always to recommended not to place business logic in action class.
Reasons are:
- Business logic becomes specific to one web application(Business logic is not reusable).
- Allows only Http clients to access the business logic. AWT application, SWING applications,Standalone Java applications are called "nonHttp applicaions".
- Middleware services(Additional services) must be implemented manually .To overcome all these problems keep business logic in EJB components are spring with Hibernate applications and make a Action class helper to controller to communicate with these model components.
Note: In most of the projects action class will be taken as helper to controller.
No comments:
Post a Comment