- This chapter will guide you through the architecture of web applications, built using JEE (Java Enterprise Edition) and Struts Framework.
- Struts is an extension of JEE technology. So these technologies follow almost same architecture and life cycle. The only differences are, the interceptors of Struts are classes in JEE and the JSP’s of Struts are servlet classes in JEE.
Struts Architecture and Life Cycle:
- Struts follows MVC (Model – View – Controller) architecture wherein (as discussed in previous chapters),
- Model: JavaBeans (Business Logic)
- View: JSP- Java Server Pages (Presentation Layer)
- Controller: Servlet (Action classes – mainly used for session handling, security, primary logic of action etc.)
Flow of Servlet Execution:
- The basic flow of request to response is:
- The client sends a request from the browser
- The controller (ActionServlet) invokes the execute() method and function responsible for intended action is called. (in turn calls interceptors)
- If required, the data is retrieved from the database by using getter and setter methods.
- A response is created by the service () method which then forwards it to intended JSP.
- The client receives the response via JSP in the browser.
- The complete scenario can be represented in sequence diagram as follows:
The request - response scenario can be visualized as follows
- The client sends request to server through a web-browser for a specific resource. This request is received by the Controller (ActionServlet).
- Interceptors are the modules which are generated to perform specific tasks such as validation, encryption – decryption, upload, download documents etc. Interceptors are based on logic. That is, if the struts application is used for validation purpose, the interceptor (Java class) will provide all the necessary steps for that operation. Even the interceptors are coordinated with each other (like thread concept in core Java) wherein, each interceptor can work together with other interceptor, can exchange results, can use commonly defined variables, can access the database (in thread-safe manner) etc. At the end of the task, the final results are again reported back to either JSP (for viewing purpose) or to the ActionServlet (for further processing purpose).
- This narrowing of tasks to sub-levels make the Struts framework based web-applications execute faster than other frameworks.