Struts provide reusable flow control logic to the maximum possible extents for any kind of web application. It provides validation support, capturing user input. Struts framework doesn’t provide any code for presentation layer.
Architectural elements are as follows.
- ActionServlet: It belongs to controller layer. It is built in class given by struts framework, it is simple HttpServlet. Struts developer should also map every request to be passed via ActionServlet.
- FormBeans: It is used for view layer. FormBeans are also known as Action form
- Action Classes: It belongs to controller layer. In a struts application for each task we have to defined a user defined class that extends given Action class. An Action class perform the following duties.
1. Capturing user input from the form bean.
2. Invoking the business method of model layer.
3. Providing view information to the Action Servlet.
4. JSP’s: It belongs to view layer.
5. Struts-config.xml: It is used to establish relationship between controller and view layer, it doesn’t belongs to any layer
Flow control in struts application
Ex. Schematic representation of a struts application in which end user entered account number into the web page and expecting account details.
Accounting Application: AccountInput.jsp, AccountFound.jsp, AccountNotFound.jsp, Exception.jsp, AccountForm.java, AccountAction.java, AccountService.java Struts-Config.xml, web.xml
System requirements to develop and execute struts application:
- Install J2EE platform (jdk 1.6 or above)
- Install Tomcat 6.x.x or above.
- Install Struts 1.x and above.
- Install eclipse or NetBean IDE.
Steps to develop a struts application
- Creating structured hierarchy of directive.
- Developing model layer as knowing all properties of all the business method of service layer.
- Developing all the JSP of the application.
- Struts-config.XML development.
What is MVC in connection with a web application ?
Any industry standard web application I.e. real time website uses three logic
- application logic
- Presentation logic
- Businesses logic
These three logic must be separated to get various benefit and to overcome various problems. Model, View & Controller is a solution for dividing these three logic. MVC is a design pattern that promote loose coupling between three concerns. It provides the following benefit
- Without effecting one concern with another we can develop application.
- Parallel development
- Re usability of code
According to MVC design pattern application logic in placed in controller, Presentation logic is view, and business logic in model. Representation of MVC in a real time web based enterprise application.
Controller receiving the client request, capturing the user input and performing server side validation for the user input.
Case 1: Validation failed controller identify appropriate input page and switch the control to that page.
Case 2: Validation Successful controller identifying the appropriate business component and it’s appropriate business method for data processing. Business method is executed and data is processed according to business rules of organization. Currently in industry the business method is belongs to either Spring Bean or EJB. Business method return the result to the controller.
Case 1: Processing is successful and the processed data is return to the controller.
Case 2: Requested data is not available and hence exception is generated to the controller.
Case 3: While processing data some abnormal events occur and this are propagated to the controller.
What is the drawbacks if we develop a web application without a framework ?
In a MVC based application, controller logic used for web application action is almost similar and difficult, if we develop application without framework then we need to develop controller for every application. A controller developed for one application can’t be reused for other application of same domain. If we develop controller without framework it is very time consuming job.
What is Struts ?
Struts is not a web technology unlike servlets, JSP it is neither J2EE nor J2SE but it uses both technology, Struts is an open source web application framework from Apache Software Foundation (ASF). Struts is used for Java based interactive websites. Struts is used for developing presentation layer for a web enabled enterprise application. Struts application means a Java based web application that follows MVC design pattern & developed using struts framework. In any Java based web application, application logic is implemented in Java language & servlets JSP are used as web technology.
What is a web application framework?
A reusable & semi finished Web application that can be customized to produce a specific web application is known as application framework. Servlets, JSP, Java Bean are the Java technologies used in struts application.
How many logics a Java based web application contains?
Web application contains three logics
- Application logic
- Presentation logic
- Business logic
1. Application logic: It is a piece of code that is responsible for the following things is known as application logic.
- Receiving the client request
- Capturing the user input
- Performing server side validation for the user input.
- Invoking the business methods
- Making processed Data available to presentation logic.
- Identifying appropriate presentation logic & switching control to the logic.
2. Presentation logic: It is the piece of code that is responsible to generate the response for the client request is known as presentation logic, it is responsible for following things.
- Accessing memory data.
- Producing dynamic web page based on the data.
Note: Most of the times user input page is development is done by presentation logic.
3. Business logic: A piece of code that process Data according to business rules of organization is known as Business Logic.
Note: Struts developer is not responsible to develops Business Logic. Struts developer basically develop application logic and presentation logic. Struts framework provide support only in areas of application and presentation logic.