Model-1 Architecture
In this Architecture, all kinds of requirements get fulfilled in one layer. The user provides the request to the JSP and JSP provides a response to the user. This architecture uses a set of JSP to implement presentation logic, business logic, controlling logic. It is suitable for small scale requirement due to its simplicity. It does not provide reusability.
Model-2 Architecture
This layer is divided into three parts they are as below
-
Model
-
Controller
-
View
- Model
This layer implements business logic and contains data. State of users can be stored in this layer. This layer can be created by using a set of java beans. - Controller
This layer implements controlling logic. It takes decision to make visible appropriate view to the appropriate users. This layer can be created by using a servlet and a set of helper classes. The users give request to the servlet present in the layer. - View
This layer implements the presentation logic of the application. It provides a response to the user. A set of JSP can be used to create this layer.
Introduction to Struts
This is a framework to implement MVC Architecture in a java based web application. It uses three different layers to implements different types of logic. It provides a set of classes and tag libraries for being used in different layers of the application.
MVC Architecture of struts
1. Model: - This layer implements business logic and contains data. This can be created by using a set of java beans called a form bean. Struts provide a predefined class as the super class of all form beans.
2. Controller: - This layer implements the controlling logic of the application. It takes the decision to make visible appropriate view to appropriate users. This can be created by using a controlling servlet and a set of helper class called form- action. Struts provide a predefined servlet as the controlling servlet. The controlling servlet receives a request from the users. Struts provide a predefined class as the super class of all form action classes.
3. View: - This layer implements presentation logic. It provides a response to the users. This layer can be created by using a set of JSP. Struts provide tag libraries for this layer.
Installation of struts
-
Get the copy of struts binary distribution (Struts 1.3.8-all.zip) from http://struts.apache.org/download.cgi and extract it into any folder of the file system.
-
Search for all .tld files in the extracted folder and makes those files available in WEB-INF folder of the context.
-
Search for all .jar files in the extracted folder and make those files available in lib folder of the context.
Configuration of struts
Create a configuration file named as struts-config.xml inside WEB-INF folder. This file contains information about form-bean, form-action, and forwards.
Tips: -
- Search for struts-config.xml inside the extracted folder of struts. Copy that file to make available in WEB-INF folder of the context. Open this file and remove all the tag present between <struts-config></struts-config>
-
Deploy the controlling servlet by using the required in WEB-INF. Name of the controlling servlet is org.apache.struts.action.Actionservlet. This servlet must accept the name of the configuration file by using an initial parameter named as config. This servlet must be a permanent servlet. This servlet must have an url-pattern to receive all types of request.
- <servlet>
- <servlet-name>x</servlet-name>
- <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
- <init-param>
- <param-name>config</param-name>
- <param-value>/WEB-INF/struts-config.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>x</servlet-name>
- <url-pattern>*.do</url-pattern>
- </servlet-mapping>

Join the conversation! Your thoughts help the community grow.