Struts Interview Questions and Answers - Freshers & Experienced!

Explain Struts.

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.

What is Action Class?

- 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 numbar of requests at same time.

What is Struts Validator Framework?

- Struts Validator Framework enables us to validate the data of both client side and server side.

- When some data validation is not present in the Validator framework, then programmer can generate own validation logic, this User Defined Validation logic can be bind with Validation Framework.

- Validation Framework consist of two XML configuration Files:
1. Validator-Rules.xml file
2. Validation.xml file

What is the need of Struts?

We need Struts in Java because of following reasons:

- Helps in creation and maintenance of the application.

- Make use 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.

- Enables developer to make use of Jakarta Packages, Java Servlets, JavaBeans, ResourceBundles, and XML.

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.

How exceptions are handled in Struts application?

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.

What is MVC?

Model View Controller (MVC) is a design pattern used to perform changes in the application.

Model: Model is referring to business or database. It stores the state of the application. Model has no knowledge of the View and Controller components.

View: View is referring to the Page Design Code. It is responsible for the showing the result of the user’s query. View modifies itself when any changes in the model happen.

Controller: Controller is referring to navigational code. Controller will chose the best action for each incoming request, generate the instance of that action and execute that action.

Describe Validate() and reset() methods.

Validate() Method:

- This method is used to validate the properties after they are explored by the application.
- Validate method is Called before FormBean is handed to Action.
- This method returns a collection of ActionError.

Syntax :
public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)

Reset() Method:

- This method is called by the Struts Framework with each request that uses the defined ActionForm.
- Used to reset all the data from the ActionForm.

Syntax :
public void reset() {}

What design patterns are used in Struts?

There are following types of design patterns are used in Struts:

- Service to Worker
- Dispatcher View
- Composite View (Struts Tiles)
- Front Controller
- View Helper
- Synchronizer Token

What is the difference between session scope and request scope when saving FormBean?

The difference between session scope and request scope when saving FormBean are following:

- In Request Scope, values of FormBean are available to current request but in Session Scope, values of FormBean are available throughout the session.

What is the different actions available in Struts?

The different kinds of actions in Struts are:

- ForwardAction
- IncludeAction
- DispatchAction
- LookupDispatchAction
- SwitchAction

What is DispatchAction?

- The DispatchAction enable the programmer to combine together related function or class.

- Using Dispatch Action programmer can combine the user related action into a single UserAction. like add user, delete user and update user.

- DispatchAction execute the action based on the parameter value it receives from the user.

How to use DispatchAction?

We can use the Dispatch Action we executing following steps:

- Create a class that extends DispatchAction.
- In a new class, add a method: method has the same signature as the execute() method of an Action class.
- Do not override execute() method.
- Add an entry to struts-config.xml

What is the difference between ForwardAction and IncludeAction?

The difference between ForwardAction and InculdeAction are:

- IncludeAction is used when any other action is going to intake that action whereas ForwardAction is used move the request from one resource to another resource.

What is difference between LookupDispatchAction and DispatchAction?

The difference between LookupDispatchAction and DispatchAction are given below:

- LookupDispatchAction is the subclass of the DispatchAction.
- Actual method that gets called in LookupDispatchAction whereas DispatchAction dispatches the action based on the parameter value.

What is LookupDispatchAction?

- The LookupDispatchAction class is a subclass of DispatchAction.
- The LookupDispatchAction is used to call the actual method.
- For using LookupDispatchAction, first we should generate a subclass with a set of methods.
- It control the forwarding of the request to the best resource in its subclass.
- It does a reverse lookup on the resource bundle to get the key and then gets the method whose name is associated with the key into the Resource Bundle.

What is the use of ForwardAction?

- The ForwardAction is used when we want to combine Struts with existing application.
- Used when we want to transfer the control form JSP to local server.
- Used to integrate with struts in order to take benefit of struts functionality, without writing the Servlets again.
- Use to forward a request to another resource in your application.

What is IncludeAction?

The IncludeAction is used to integrate the one action file in another action file.

- It is same as ForwardAction but the only difference is that the resource is present in HTTP response.
- Is used to combine the Struts functionality and control into an application that uses Servlets.
- Use the IncludeAction class to include another resource in the response to the request being processed.
1 2 3 4 5

What is Jakarta Struts Framework?
Jakarta Struts Framework - An open source framework for creating web applications. Web applications, some deliver static content and some create dynamic response.....
Components of Struts
Components of Struts - Model Components, View Components, Controller Components.....
Core classes of the Struts Framework
Core classes of the Struts Framework - The core classes of Struts framework are: ActionServlet, ActionForm, Action, Action Mapping, ActionForward.....
Post your comment
Discussion Board
Great Explanation..
Very useful..
Vijay 08-29-2015
Struts
Thank you sir .This question useful for my interview.
S.Poongodi 08-18-2015
thank u
Your explanation is good.thank u so much.
harikanth 05-9-2014
Struts.
Thank you.:)

Its very useful for the interview and understanding the basic functionality of the struts.
pankaj kumar 04-25-2014
Struts
Thanks a lot sir. You thought other to develop where as other thought for their self devolopment
Manoj kumar Khanda 09-12-2013
Struts
Hi sir its really uses of interview point and normal learn on struts

Thanks sir
M R Siva
E-mail:sivasoft.java@gmail.com
siva 05-24-2013
Reg:Java/Struts 82 Q&A
It is really useful for facing interview,I got bit confident before my interview round..
sravan kumar.s 03-24-2013
Struts
thanks you very much sir...........
venkatakrishna 02-21-2013