Struts is open source software used to develop java based web page.
Struts uses Jakarta Packages, Java Servlets, JavaBeans, ResourceBundles, and XML
Struts takes the help of Model View Controller (MVC) architecture. Where Model is referring to business or database, View is referring to the Page Design Code, and Controller is referring to navigational code.
An Action class in the struts application is used to handle the request.
It acts as interface or communication medium between the HTTP request coming to it and business logic used to develop the application. Action class consists of RequestProcessor which act as controller. This controller will choose the best action for each incoming request, generate the instance of that action and execute that action. This should be in thread-safe manner, because RequestProcessor uses the same instance for no. of requests at same time.
Exceptions are handled in struts by using any one of the following two ways:
Programmatically handling: In this exception are handled by using try and catch block in program. Using this programmer can define how to handle the situation when exception arises.
Declarative handling: In this exception handling is done by using the XML file. Programmer defines the exception handling logic in the XML file. There are two ways of defining the exception handling logic in the XML file:
-Global Action Specific Exception Handler Definition.
-Local Action Specific Exception Handler Definition.
In action mapping is the mapping of the action performed by the user or client on the application.
-We specify the action class for a specific user’s action. Like we provide the path or URL and different view based on user event.
-We can also define where control of the page deviate in case of validation error in the form.
-We can include ActionMapping in code like this:
Validation error: Validation error are those error which arises when user or client enters the invalid format data into the form. For this validation of data struts enables the programmer with the Validator() method which validates both the data from client side and the server side.
We can display all error in the JSP page by using the following syntax in the code.
We can combine Struts and Velocity template by performing following steps:
1. Set classpath to Velocity JARs
2. Make web.xml file to identify the Velocity servlet
3. Select Velocity toolbox.xml in WEB-INF directory.
4. Modify struts-config to point its views to Velocity templates instead of JSPs.
5. Create a Velocity template for each page you want to render.