Struts Interview Questions and Answers
Most Frequently Asked Struts Interview Questions
ActionMapping represents the information that is known to RequestProcessor about the mapping of a specific request to a specific Action class. This instance is used to select an Action and then passing on to that Action, thus providing access to configuration information included in the ActionMapping object.
Struts use the model 2 MVC architecture. The controller takes the command design pattern and the action classes have the adapter design pattern. In addition, the process() method of RequestProcessor uses template method design pattern.
This framework also implements the J2EE design patterns:
- Service to Worker
- Dispatcher View
- Composite View (Struts Tiles)
- Front Controller
- View Helper
- Synchronizer Token
The Struts framework uses one or more configuration files to load and create required application-specific components. These configuration files allow the components to be declaratively specified, rather than having hardcoded behavior and information. This can give you the flexibility to provide your own extensions. Based on XML format, configuration files can be validated against Struts DTD.
We can configure with the help of few important configuration files like struts.xml, web.xml,strutsconfig.xml and struts.properties
S.no | Validator-rules.xml | Validation.xml |
---|---|---|
1. | Defines standard validation routines | Defines validations that apply to form bean |
2. | For global specific rules | For application specific rules |
3. | Contain logic for validation | Contains types of validation |
Validation error arises when a user enters invalid data format into the form. In order to validate this data, Struts enables the developer or programmer with the Validator() method for validating the data from the client side as well as the server side. You can display errors in the JSP page by using this syntax: SYNTAX: <html:error/>
In Struts, DynaActionForm is a feature which allows the dynamic creation of ActionForm beans through the XML configuration. In such applications, Form beans are virtual and not hard-coded ActionForm classes.
This reduces the tedious process of managing and creating ActionForm classes.
Tiles are used for creating reusable presentation components. When using Tiles, first define a base layout with various sections. Next, define jsp page that should fill the corresponding regions in an external configuration file.
There are two ways to specify definition and attributes of Tiles - JSP Tile Definition and XML Tile Definition.
OGNL or Object-Graph Navigation Language is an open-source Expression Language that allows the navigation of objects (through syntax) for specifying symmetrically settable values. The syntax provides a high level of abstraction for navigating object graphs. This feature allows for simple array manipulation.
Technically, there is no difference between them Apache Struts and Jakarta Struts. They are both similar. Craig McClanahan created Struts and donated it to Apache Foundation. Later, it evolved as a Jakarta project and gained popularity in the J2EE community.
There are 5 core classes in Struts framework:
- ActionServlet
- ActionForm
- Action
- Action Mapping
- ActionForward
This is one of the most repeatedly asked Java Struts 1.2 interview questions and answers.