If you're looking for Struts Interview Questions for Experienced or Freshers, you are at right place. There are lot of opportunities from many reputed companies in the world. According to research Struts has a market share of about 1%. So, You still have opportunity to move ahead in your career in Document Object Model in Apache Struts. Mindmajix offers Advanced Struts Interview Questions 2018 that helps you in cracking your interview & acquire dream career as Struts Developer.
Q: What do you mean by the term Struts?
Struts can be defined as open source software that can be used for developing web pages that are java based. Struts uses different components and packages like XML, Jakarta Packages, JavaBeans, ResourceBundles etc. Struts use the Model View Controller (MVC) architecture as a support. In this case by Model it is being talked about a business or a database, with View it is being referred to a page design code and lastly the controller means the navigational code.
Q: What is meant by Action Class?
In a Struts application the action class handles the requests. The action class is the interface between the request (HTTP) and the logic used for developing the application. The RequestProcessor in the action class works as the controller which chooses the proper action for the requests that are received.
Q: Describe the different components of Struts.
The struts framework has the following components:
1. Java Servlets
2. Custom Tags
3. JSP (Java Server Pages)
4. Message Resources
Q: How the flow of requests takes place in Struts Application?
Struts Applications use the MVC designs and the flow of request happens in this way:
** The user interacts with the view after clicking on a link or after they submit a form.
** After the interaction takes place, the request is forwarded to the controller.
** The controller is the person held responsible for forwarding the request for a better action.
** Action class decides the function which further works for the business logic that is to be implemented.
** The last step is the response, it occurs after the model layer sends it and it is viewed on the screen by the user.
Q: What are the two different validations that the Validator Framework supports?
For the purpose of Validation of form data, Validator framework is used. The two different validations are:
1. Client Side Validation
2. Server Side Validation
Q: How to control submission of duplicate forms in Struts?
In Struts, two different methods are used in order to stop submission of duplicate forms. These methods are provided by the action class:
saveToken() is the first method that is provided by the action class for generating a unique token that is further saved under the user’s session.
isTokenValid() is another method that is used while one wants to check the uniqueness of the tokens.
Q: What do you mean by DynaActionForm?
DynaActionForm is a sub-class of the ActionForm class which is used for the creation of form beans dynamically. It takes help of the configuration files in order to create the form beans.
Q: Name all the core classes in Struts Framework.
The Core classes in Struts Framework are:
1. Action Servlet: This is the most important part of the whole application since it works as the backbone of the framework.
2. ActionForm: This is a Java Bean and it is used for referring to forms.
3. Action Class: This is used for handling all the requests.
4. Action Mapping: This is used for the process of mapping within the object and the action.
5. ActionForward: This forwards the results from the controller to the destination.
Q: Describe the benefits of the Struts framework.
The struts framework is completely working on the MVC architecture. This ensures that the different layers of Struts are separated properly which further ensures the development and the customisation of application easy. Because files of different configurations are used thus the configuration of applications also becomes easy. Struts framework is also open source software and thus the best part, it is cost effective!
Q: Why do we need struts?
The reasons for which we need Struts are:
** This helps the programmers and developers in the creation of the application and also the maintenance.
** This uses Model View Controller (MVC) architecture, which is a big plus point in case of a framework.
** This will also give you the liberty to use Jakarta Packages, JavaBeans, XML, Java Servlets etc.
Q: What is the ForwardAction used for?
When we want to combine an existing application with struts, we need to use the ForwardAction. ForwardAction is also used whenever one wants to transfer the complete control from one place to another, say, JSP to a local server. The ForwardAction is also used when one wants to obtain the benefits of functionality of struts after the integration with struts. In this case, Servlets are never written again. Another use of ForwardAction is when a request is forwarded to other resources.
Q: What are the uses of ActionClass?
The action class included in the Strut application is responsible for handling requests. The action class acts like the medium or interface within the HTTP requests that are coming and the business logic that is used for developing the application. Request Processor in the Action Class acts as the major controller and is the single controller of Struts framework. The controller selects the actions for the requests that are received, then generates a result for the request or action and lastly executes the action.
Q: When should you use Struts Framework?
You should opt for struts framework when the given conditions are fulfilled:
>> Firstly an application development of very high level robust enterprise is necessary.
>> An application is required that can be reused and is configurable completely or to certain level.
>> An application is required which is MVC based, is coupled very loosely and also has a clear segregation within the different layers.
Q: How can you use resourcebundle.properties file for Struts Validation framework?
In order to define certain error messages resourcebundle.properties file is required. It is done in input value pairs. This is done for checking all the errors in the whole coding that may have slipped. This way it is ensured that the code is clean since the developer no longer has to worry about the embedded error messages in the code.
Q: What is the difference between Apache Struts and Jakarta Struts?
If you are asked about this, then remember this is a trick question. There is absolutely no difference between the two, they are the same.
Q: Describe the two types of Formbeans.
There are two different types of Formbeans:
** Request Scope: When the Scope type is request, the values of the formbeans are available with the current request.
** Session Scope: When the scope type is session, the values of the formbeans are found for all the requests in the recent session.
Q: How to migrate an application from “Strut 1” to “Strut 2”.
There are multiple steps for migration of an application from the strut 1 to strut 2. The steps are:
Firstly you have to move the Strut 1 Action form.
After moving it, you have to place it in Strut 2 POJO.
Then you have to convert the configuration file of struts 1 i.e. struts-config.xml into the configuration file of struts 2 i.e. struts.xml
Q: Name the different technologies for the View Layer.
There are many different technologies that can be used in the view layer. Some of them are:
3. Velocity Templates
5. WML Files
Apart from this many other technologies can be also used, but these are the primary ones used for the view layers.
Q: Explain the complete Struts Validator Framework.
The Struts Validator Framework helps us in validating the data for both the client’s side and the server’s side. If some data is missing while validation or some data is not validated, the programmer is free to add their own concept or logic for validation. This validation logic is further bind with the framework. The validation framework has two different XML files-
Validator-Rules.xml file and Validation.xml file.
Q: What do you mean by Dispatch action and how do we use it?
The Dispatch action is responsible for allowing the programmer for combining two related functions or classes. With the help of this action, the programmer can also combine two similar actions and make one major or User action. It can be used for creating a class for extending the action. It can also be used for addition of a method with a similar signature like execute method.
Q: Describe the drawbacks in the Struts framework.
The different drawbacks in Struts are:
>> There is an absence of the flow mechanism in the backward direction.
>> This uses only one controller servlet.
>> There is no exception found in the framework.
>> The Struts Framework is not very transparent.
>> The documentation is very bad in case of struts framework.
Q: What is meant by Custom Tags?
These are customised tags by the users that they can use in the application depending on their needs. If a JSP page with custom tags or user defined tags is translated then the custom also gets translated. Because the tags are reusable, they also help in better development.
Q: State the differences between Struts 1 and Struts 2.
The main differences between the two Struts are:
** The controller used by the both Struts are different, ActionServlet is used by Strut 1 and Filter by Strut 2.
** For mapping the forms (JSP), Struts1 uses ActionForm. However in case of Struts 2 no such ActionForm is available.
** In case of Strut 1 for validation of data,
Validation () method is used but for Strut 2 it is done by the Validation framework.
Q: What is meant by Action Errors?
During the submission or fill-up of a form, is a client or user makes a mistake in the data for the application that is known as Action Error. The client or user is solely responsible for them. They should be checked as early as possible. If they are not detected fast, they will waste server time and have a bad effect on quality of codes.
Q: Mention the steps for combining Velocity templates and Struts.
In order to combine Velocity templates and Struts, follow the steps:
1. First you have to set the classpath into Velocity JARs.
2. Then you need to make the web.xml for identifying Velocity servlet.
3. In the WEB-INF directory you have to choose velocity toolbox.xml
4. In order to point the view of struts-config from JSPs to velocity templates you need modifications.
5. For every page that needs to be rendered create the velocity template.
Q: How can you show validation errors on the JSP page?
These are the errors that appear when a client or user enters wrong or invalid data for filling up the application. At that moment, for validation the method of
Validator() is used which works for the validation on both sides. In order to display the errors on JSP page the syntax code is .
Q: Name the different actions found in Struts.
The different actions found in Struts are:
Q: What is meant by LookupDispatchAction?
This is a subclass under the DispatchAction class. This is required for calling the actual methods. For using the LookupDispatchAction, we need a certain set of rules and methods. This controls the forward mechanism by sending the request to the proper resource.
Q: Name the different libraries for Strut tags.
The different Strut tag libraries present are:
1. Bean Tags: This is used for accessing bean and also their properties.
2. HTML Tags: This is necessary for the creation of struts forms and GUI of the web pages.
3. Logic Tags: This is used for performing all the logical operations.
4. Nested Tags: This is used for performing all the nested functions.
Q: Mark the differences between HTML tags and Strut specific HTML Tags.
The differences between the both are:
1. The nature of HTML tags is Static whereas the nature of Struts specific HTML tags is dynamic.
2. HTML is an integrated in Struts but Struts have their own tag libraries.
3. The tags for HTML cannot be user defined but in case of Struts the tags can be user defined.
Get Updates on Tech posts, Interview & Certification questions and training schedules