82 struts interview questions and answers

Struts interview questions and answers for freshers and experienced candidates. Also find Struts online practice tests to fight written tests and certification exams on Struts. In this section we have covered almost all Struts questions that might be asked during an interview.
          

Struts interview questions and answers


Part 1   Part 2   Part 3   Part 4   Part 5
<<Previous  Next>> 
Struts interview questions answers - contributed by Rohit Srivastava

Q1. 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.

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

Q3. 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:
    o Validator-Rules.xml file
    o Validation.xml file

Q4. 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

Q5. 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.

Q6. 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.

Q7. 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.

Q8. 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() {}

Q9. 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

Q10.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.

Q11.What is the different actions available in Struts?

The different kinds of actions in Struts are:

  • ForwardAction
  • IncludeAction
  • DispatchAction
  • LookupDispatchAction
  • SwitchAction

Q12.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.

Q13. 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

Q14. .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.

Q15.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.

Q16.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.

Q18. 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

Q19.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.

Q20. 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

Q21. 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

Q22. 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

Q23. Difference between Html tags and Struts specific HTML Tags

Difference between HTML tag and Struts specific HTLM tags are:

  • HTML tags are static in nature but Struts specific HTML tags are dynamic in nature.
  • HTML tags are not User Defined whereas Struts tags can be user defined.
  • HTML tags provide the different templates and themes to the programmer whereas Struts specific HTML tag provides the integrating the property value with the Formbean properties.
  • HTML tags are integral part of Struts whereas Struts have HTML tag libraries.

Q24. 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.

Q25. How to display validation errors on JSP page?

Validation error: Validation error are those error which arises when user or client enters the invalid format data into the form. For this validation of data struts enables the programmer with the Validator() method which validates both the data from client side and the server side.

We can display all error in the JSP page by using the following syntax in the code.

SYNTAX: <html:error/>

Q26. 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:

<global-forwards>
<statements>
<forward name="CitizenDetailsPage"
path="/gotoCitizenDetails.do" />
</global-forwards>

<action-mappings>
<statements>
<action path=”/gotoCitizenDetails”
parameter=”/CitizenDetails.jsp”
type=”org.apache.struts.actions.ForwardAction” />
</action-mappings>

Q27. What is ActionMapping?

In action mapping is the mapping of the action performed by the user or client on the application.

-We specify the action class for a specific user’s action. Like we provide the path or URL and different view based on user event.
-We can also define where control of the page deviate in case of validation error in the form.
-We can include ActionMapping in code like this:
<action-mappings>
<action path="/a" type=myclasse.A name="myForm">
<forward name="Login" path="/login.jsp"/>
<forward name="error" path="/error.jsp"/>
</action-mappings>

Q28. What is role of 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 no. of requests at same time.

Q29. How to combine the Struts with Velocity Template?

We can combine Struts and Velocity template by performing following steps:

1. Set classpath to Velocity JARs
2. Make web.xml file to identify the Velocity servlet.
3. Select Velocity toolbox.xml in WEB-INF directory.
4. Modify struts-config to point its views to Velocity templates instead of JSPs.
5. Create a Velocity template for each page you want to render.

Q31. In how many ways duplicate form submission can occurs?

The submission form can be duplicated by the any of the following ways:

  • Using refresh button.
  • By clicking submit button more than once before the server sent back the response.
  • By clicking back navigation button present in browser.
  • The browser is restores to submit the form again.
  • By clicking multiple times on a transaction that is delayed than usual.

Q32. What is the difference between Struts 1 and struts2?

The difference between struts1 and struts2 are below:

  • Struts1 uses ActionServlet as Controller where as Struts2 uses Filter as a controller.
  • Struts1 uses the ActionForm for mapping the JSP forms but in struts2 there no such ActionForm.
  • Struts1 uses Validation() method to validate the data in the page forms where as struts 2 validation of data is ensure by Validator Framework.
  • In Struts 1 the bean and logic tag libraries are often replaced by JSTL, but Struts 2 has such tag libraries that we don’t need to use JSTL.

Q33. What are the steps used to setup dispatch action?

To setup the dispatch action the following steps are used:

  • Create a subclass for DispatchAction.
  • Create method for logical action and their related actions.
  • Request Parameter is created for each action.
  • Define ActionMapping.
  • The JSP takes on the subclass defined for dispatch action method names as their values

Q34. What is difference between Interceptors and Filters?

The difference between Interceptors and filter are below:

  • Filters are based on Servlet Specification whereas Interceptors are based on Struts2.
  • Filters are executed only when patter matches whereas Interceptors executes for all request qualifies for a front controller.
  • Filters are not Configurable method calls whereas Interceptors methods can be configured.

Q35. What are the Custom tags?

Custom Tags are User Defined Tags, which means that user can create those tags depending upon their need in the application.

  • When a JSP page consisting of user- defined or custom tag is translated into a Servlet, the custom is also get translated into operation
  • Help in fast development of the application due to custom tag reusability.

Q36. 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.

Q37. What is the difference between RequestAware and ServletRequestAware interface?

The difference between RequestAware and ServletRequestAware are:

  • RequestAware enables programmer with the attributes in the Servlet Request as a map whereas ServletRequestAware enables programmer with HttpServletRequest object.
  • ServletRequestAware are more flexible than RequestAware.
  • ServletRequestAware makes action class highly coupled with Servlet environment which is not possible in RequestAware.

Q38. What are inner class and anonymous class?

Inner class: classes that are defined within other classes.

  • The nesting is a relationship performed between two different classes.
  • An inner class can access private members and data.
  • Inner classes have clearly two benefits:
    o Name control
    o Access control.
    Anonymous class: Anonymous class is a class defined inside a method without a name.
  • It is instantiated and declared in the same method.
  • It does not have explicit constructors.

Q39. 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.

Q40. 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.


 

41.What is Jakarta Struts Framework?

Latest answer: An open source framework for creating web applications. Web applications, some deliver static content and some create dynamic response. A web application can perform database actions and perform business logic to make responses customized...........
Read answer

42. Describe the components of Struts.

Latest answer: Model Components: Many application’s focus is on the view. The processing required for each submitted form / request by keeping the model’s perspective in view............
Read answer

Test your Java skills

Java part 1 (39 questions)
Java part 2 (40 questions)
EJB (20 questions)
JDBC (20 questions)
Applet (20 questions)
Struts (21 questions)
Servlets (20 questions)
Java web services (20 questions)

43. Explain the core classes of the Struts Framework.

Latest answer: The core classes of Struts framework are:
ActionServlet, ActionForm, Action, Action Mapping, ActionForward...........
Read answer

44. What are the drawbacks of Struts?

Latest answer: Drawbacks of Struts:

  • No backward flow
  • Single controller servlet – Only one ActionServlet is available which may be an issue of scalability..........
    Read answer
45. Explain Struts navigation flow.

Latest answer: When an action servlet gets the request, it initiates the servlet-config.xml
It selects an appropriate page as per the mapping..............
Read answer

46. Explain the design patterns used in Struts.

Latest answer: The Struts design pattern has N-tier architecture. This includes MVC architecture, Web applications characters, struts framework which includes – architecture, design patterns and coding idioms.............
Read answer

47. Explain the different kinds of actions in Struts.

Latest answer: The different kinds of actions are done by the following:
DispatchAction, ActionDispatcher , LookupDispatchAction..............
Read answer

48. What is Action Class?

Latest answer: This class is extended by the org.apache.struts.action.Action class. The business logic is wrapped by the Action class and this class provides an interface to the Model of the application................
Read answer

49. What is ActionForm?

Latest answer: ActionForm is a Java bean that associates one or more ActionMappings. The bean is initialized from the corresponding parameters of requests well before the Action.execute method is invoked............
Read answer

50. Describe the main difference between Action and DispatchAction classes.

Latest answer: Grouping related actions into one class is possible using DispatchAction class. But in Action class a group related action into one class is not possible..Several changes need to be done, when one plans to group the related action using Action class.............
Read answer

51. What is switch action & forwardAction in struts?

Latest answer: A SwitchAction is like an Action which switches between modules and forwards the control to the URI that is specified in the new module............
Read answer

52. What is LookupDispatch Action?

Latest answer: LookupDispatch is similar to ActionDispatch. It distinguishes the ActionDispatch that uses the request parameter’s values which performs a reverse lookup from resource bundle which uses the value of parameters and match it to a method in the class..............
Read answer

53. Explain the difference between ForwardAction and IncludeAction.

Latest answer: Forwarding to a specified URL is provided by the ForwardAction. The mechanism to include the specified URL contents is proveided by the IncludeAction...........
Read answer

54. Explain the difference between Html tags and Struts specific HTML Tags.

Latest answer: HTML tags are static and Struts tags are dynamic.
Struts tags can be created by the page authors............
Read answer

55. What are the contents of web.xml and struts-config.xml? Explain the difference between them.

Latest answer: The web.xml file contains the information that is used by servlets and JSPs. The file includes the description of the application, information about servlets, mapping information for servlets and URL, JSP configuration information...............
Read answer

56. Differences between web.xml and sturts-config.xml

Latest answer: web.xml is utilized to make connections between web application and the web container, where as the struts-config.xml is utilized to establish the connections between the controller and the view of MVC architecture.............
Read answer

57. Explain how to communicate from struts to ejb.

Latest answer: The Struts framework strictly implements MVC pattern. The execute() method of Action class can be invoked to interact with the Model part of MVC. An EJB may contain a model. The model methods can be invoked by the execute() method............
Read answer

Struts and Ajax

Struts Interview questions - August 02, 2008, 17:00 pm by Amit Satpute
58.Define Struts.

Latest answer: Struts is a framework for creating Java web applications. Web applications differ from conventional websites in that web applications can create a dynamic response. Due to the blend of database, design and control flow codes of JSP, the larger applications become difficult to maintain.............
Read answer

59.What are action form classes in Struts?

Latest answer: The Action is part of the controller. Action Class is used to translate the HttpServletRequest to the business logic. To do this we need to overwrite the execute() method..............
Read answer

60.What is ActionServlet?

Latest answer: It is a class in org.apache.struts.action. It plays the role of a controller in the Jakarta Struts Framework..........
Read answer

61.What is Struts Validator Framework?

Latest answer: The validation of data, whether on the Client side browser form or on the server side, can be done with the help of Struts Validator Framework.............
Read answer

62.Explain directory structure for a struts folder.

Latest answer: META-INF: Contains meta information. Used by utilities etc.
WEB-INF/classes: This is where you place you own Java classes.
WEB-INF/classes/ApplicationResources.properties: Contains the messages (fixed texts) of the application. Error messages are also put here.............
Read answer

Test your struts knowledge with our multiple choice questions!
<<Previous  Next>>

Test your Java skills

Java part 1 (39 questions)
Java part 2 (40 questions)
EJB (20 questions)
JDBC (20 questions)
Applet (20 questions)
Struts (21 questions)
Servlets (20 questions)
Java web services (20 questions)

Also read

OFBiz Service Engine

Defining and creating a Java service
Service parameters
Special unchecked (unmatched) IN/OUT parameters
Security-related programming
Calling services from code (using dispatcher)
IN/OUT parameter mismatch when calling services
Sending feedback; standard return codes success, error and fail
Implementing Service Interfaces
Synchronous and asynchronous services
Using the Service Engine tools
ECAs: Event Condition Actions

Write your comment - Share Knowledge and Experience

Discussion Board
Struts

Thanks a lot sir. You thought other to develop where as other thought for their self devolopment

Manoj kumar Khanda 09-12-2013 12:29 AM

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 08:10 PM

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 04:01 PM

Struts

thanks you very much sir...........

venkatakrishna 02-21-2013 12:14 AM

 

 
Interview questions
 
Home | Want a Job? Submit Key Skills | Employer login | My key skills | About us | Sitemap | Contact us