What is Struts?
The core of the Struts framework is a flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and XML, as well as various Jakarta Commons packages. Struts encourages application architectures based on the Model 2 approach, a variation of the classic Model-View-Controller (MVC) design paradigm.
Struts provides its own Controller component and integrates with other technologies to provide the Model and the View. For the Model, Struts can interact with standard data access technologies, like JDBC and EJB, as well as most any third-party packages, like Hibernate, iBATIS, or Object Relational Bridge. For the View, Struts works well with JavaServer Pages, including JSTL and JSF, as well as Velocity Templates, XSLT, and other presentation systems.
The Struts framework provides the invisible underpinnings every professional web application needs to survive. Struts helps you create an extensible development environment for your application, based on published standards and proven design patterns.
What are the components of Struts Framework?
Struts framework is comprised of following components:
JSP (Java Server Pages)
What is Jakarta Struts Framework?
Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.
Which file is used by controller to get mapping information for request routing?
Controller uses a configuration file “struts-config.xml file to get all mapping information to decide which action to use for routing of user’s request.
What are the steps of Struts Installation?
In order to use Struts framework, we only need to add Struts.Jar file in our development environment. Once jar file is available in the CLASSPATH, we can use the framework and develop Strut based applications.
How duplicate form submission can be controlled in Struts?
In Struts, action class provides two important methods which can be used to avoid duplicate form submissions.
saveToken() method of action class generates a unique token and saves it in the user’s session. isTokenValid() method is used then used to check uniqueness of tokens.
What’s the difference between validation.xml and validator-rules.xml files in Struts Validation framework?
In Validation.xml, we define validation rules for any specific Java bean while in validator-rules.xml file, standard and generic validation rules are defined.
How can we display all validation errors to user on JSP page?
To display all validation errors based on the validation rules defined in validation.xml file, we use <html:errors /> tag in our JSP file.
DynaActionForm is a special type of actionForm class (sub-class of ActionForm Class) that’s used for dynamically creating form beans. It uses configuration files for form bean creation.
What’s the use of Struts.xml configuration file?
Struts.xml file is one the key configuration files of Struts framework which is used to define mapping between URL and action. When a user’s request is received by the controller, controller uses mapping information from this file to select appropriate action class.
What are the benefits of Struts framework?
Struts is based on MVC and hence there is a good separation of different layers in Struts which makes Struts applications development and customization easy. Use of different configuration files makes Struts applications easily configurable. Also, Struts is open source and hence, cost effective.
What’s the use of resourcebundle.properties file in Struts Validation framework?
resourcebundle.properties file is used to define specific error messages in key value pairs for any possible errors that may occur in the code.
This approach helps to keep the code clean as developer doesn’t need to embed all error messages inside code.
How many servlet controllers are used in a Struts Application?
Struts framework works on the concept of centralized control approach and the whole application is controlled by a single servlet controller. Hence, we require only one servlet controller in a servlet application.
What are the Core classes of Struts Framework?
Following are the core classes provided by Struts Framework:
When should be opt for Struts Framework?
Struts should be used when any or some of the following conditions are true:
A highly robust enterprise level application development is required.
A reusable, highly configurable application is required.
A loosely coupled, MVC based application is required with clear segregation of different layers.
Why ActionServlet is singleton in Struts?
In Struts framework, actionServlet acts as a controller and all the requests made by users are controlled by this controller. ActionServlet is based on singleton design patter as only one object needs to be created for this controller class. Multiple threads are created later for each user request.
What are the conditions for actionForm to work correctly?
ActionForm must fulfill following conditions to work correctly:
-It must have a no argument constructor.
-It should have public getter and setter methods for all its properties.
What is Struts Validator Framework?
Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class.
The Validator framework was developed by David Winterfeldt as third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.
Give the Details of XML files used in Validator Framework?
The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean.
What are the classes used in Struts?
Struts Framework consists of following classes:
Action Servlets: Used to control the response for each incoming request.
Action Class: Used to handle the request.
Action Form: It is java bean, used to referred to forms and associated with action mapping.
Action Mapping: Used for mapping between object and action.
Action Forward: Used to forward the result from controller to destination.
What design patterns are used in Struts?
There are following types of design patterns are used in Struts:
Service to Worker
Composite View (Struts Tiles)
What is the different actions available in Struts?
The different kinds of actions in Struts are:
What are the various Struts tag libraries?
The various Struts tag libraries are:
HTML Tags: used to create the struts input forms and GUI of web page.
Bean Tags: used to access bean and their properties.
Logic Tags: used to perform the logical operation like comparison.
Template Tags: used to changes the layout and view.
Nested Tags: used to perform the nested functionality.
Tiles Tags: used to manages the tiles of the application.
What are the loop holes of Struts?
The drawbacks of Struts are following:
Absence of backward flow mechanism.
Only one single controller Servlets is used.
Bigger learning curve.
No exception present in this framework.
With struts 1, embedding application into JSP can’t be prevented.
Non-XML compliance of JSP syntax.
What steps are required to for an application migration from Struts1 to Struts2?
Following Steps are required for Struts1 to Struts2 migration:
Move Struts1 actionForm to Struts2 POJO.
Convert Struts1 configuration file (struts-config.xml) to Struts2 configuration file (struts.xml)
How properties of a form are validated in Struts?
For validation of populated properties, validate() method of ActionForm class is used before handling the control of formbean to Action class.
What’s the flow of requests in Struts based applications?
Struts based applications use MVC design pattern. The flow of requests is as follows:
User interacts with View by clicking any link or by submitting any form.
Upon user’s interaction, the request is passed towards the controller.
Controller is responsible for passing the request to appropriate action.
Action is responsible for calling a function in Model which has all business logic implemented.
Response from the model layer is received back by the action which then passes it towards the view where user is able to see the response.
What’s the role of Action Class in Struts?
In Struts, Action Class acts as a controller and performs following key tasks:
After receiving user request, it processes the user’s request.
Uses appropriate model and pulls data from model (if required).
Selects proper view to show the response to the user.