+91 90691 39140 | +1 253 214 3115 | info@hub4tech.com | hub4tech

Struts Interview Questions and Answers

1
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.
2
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:
    • Validator-Rules.xml file
    • Validation.xml file
3
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
4
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.
5
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.
6
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 of Validate() Method:
    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 of Reset() Method:
    public void reset() {}

7
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
8
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.
9
What is the different actions available in Struts?

The different kinds of actions in Struts are:

  • ForwardAction
  • IncludeAction
  • DispatchAction
  • LookupDispatchAction
  • SwitchAction
10
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.
11
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.
12
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
13
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
14
What is the life cycle of ActionForm?

The lifecycle of ActionForm is as follows:

  • Retrieve or Create Form Bean associated with Action
  • "Store" FormBean in appropriate scope (request or session)
  • Reset the properties of the FormBean
  • Populate the properties of the FormBean
  • Validate the properties of the FormBean
  • Pass FormBean to Action
15
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
  • Worst documentation
  • No exception present in this framework
  • Less transparent
  • Rigid approach.
  • With struts 1, embedding application into JSP can’t be prevented.
  • Non-XML compliance of JSP syntax
16
How to use forward action to restrict a strut application to MVC?

We can use the ForwarAction to restrict the Struts application to Model View Controller by following coding:

17
What is struts.devMode?

The struts.devMode is used to make sure that framework is running in development mode or production mode by setting true or false. struts.devMode is set to false in production phase to reduce impact of performance. By default it is "false". It is used because of the following reasons:

  • Resource Reloading: Resource bundle reload on every request
  • Modification: struts.xml can be modified without restarting or redeploying the application
  • Error Handling: The error occurs in the application will be reported, as oppose to production mode.
18
What is the difference between empty default namespace and root namespace?

The difference between the empty default namespace and root name space are:

  • When namespace attribute is not defined then it is referred to as Empty Default Namespace whereas when name space attribute is assign with forward slash(/) then it is referred to as Root Name Space.
  • The root namespace must be matched.
19
What are action errors?

Action error: when user or client submits the incorrect or invalid data in the application, then these errors are known as Action error.

  • Action errors are generated by the clients.
  • Action error should be determined as soon as possible.

The impacts of such Action Error are:

  • Wastage of server time and resources.
  • Negative impact on code quality.
Copyright ©2015 Hub4Tech.com, All Rights Reserved. Hub4Tech™ is registered trademark of Hub4tech Portal Services Pvt. Ltd.
All trademarks and logos appearing on this website are the property of their respective owners.
FOLLOW US