0% found this document useful (0 votes)
687 views

Struts2 Interview Questions and Answers

Struts2 Interview Questions and Answers discusses differences between Struts 1 and 2, design patterns used in Struts 2 like interceptors, MVC architectures followed by Struts frameworks, threading issues with interceptors, differences between interceptors and filters, the front controller class in Struts 2, the role of actions and models, how interceptors improve Struts 2, the relation between the value stack and OGNL, configuring annotation-based actions, the purpose of devMode, getting request objects in interceptors, differences between the Action and ActionSupport classes, and the execute and wait interceptors.

Uploaded by

narender1818
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
687 views

Struts2 Interview Questions and Answers

Struts2 Interview Questions and Answers discusses differences between Struts 1 and 2, design patterns used in Struts 2 like interceptors, MVC architectures followed by Struts frameworks, threading issues with interceptors, differences between interceptors and filters, the front controller class in Struts 2, the role of actions and models, how interceptors improve Struts 2, the relation between the value stack and OGNL, configuring annotation-based actions, the purpose of devMode, getting request objects in interceptors, differences between the Action and ActionSupport classes, and the execute and wait interceptors.

Uploaded by

narender1818
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Struts2 Interview Questions and Answers

1. What is the difference between Struts 1 vs Struts 2 ?

http://struts.apache.org/2.1.6/docs/comparing-struts-1-and-2.html

2. Which design pattern the Interceptors in Struts2 is based on ?

Interceptors in struts are based on Intercepting Filters.

3. What are Pull-MVC and push-MVC based architecture ? Which architecture does
Struts2 follow ?

Pull-MVC and Push-MVC are better understood with how the view layer is getting
data i.e. Model to render. In case of Push-MVC the data( Model) is constructed and
given to the view layer by the Controllers. Typical example is Spring MVC and
Struts1. Pull-MVC on the other hand puts the model data typically constructed in
Controllers are kept in a common place , which then gets rendered by view
layer. Struts2 is a Pull-MVC based architecture, in which all data is stored in Value
Stack and retrieved by view layer for rendering.

4. Are Interceptors in Struts2 thread safe ?

No,Unlike Struts2 action, Interceptors are shared between requests, so thread issues
will come if not taken care of.

5. Are Interceptors and Filters different ? , If yes then how ?


6. In Struts1, the front-controller was a Servlet but in Struts2, it is a filter. What is the
possible reason to change it to a filter ?
7. Which class is the front-controller in Struts2 ?

The class "org.apache.struts2.dispatcher.FilterDispatcher " is the front controller in


Struts2. In recent time Struts 2.1.3 this class is deprecated and new classes are
introduced to do the job. Refer:  http://struts.apache.org/2.1.8/struts2-
core/apidocs/org/apache/struts2/dispatcher/FilterDispatcher.html
 

8. What is the role of Action/ Model ?

Actions in Struts are POJO , is also considered as a Model. The role of Action are to
execute business logic or delegate call to business logic by the means of action
methods which is mapped to request and contains business data to be used by the
view layer by means of setters and getters inside the Action class and finally helps
the framework decide which result to render
9. How does Interceptors help achieve Struts2 a better framework than Struts1 ? 
10. What is the relation between ValueStack and OGNL ?

A ValueStack is a place where all the data related to action and the action itself is
stored. OGNL is a mean through which the data in the ValueStack is manipulated.

11. Can annotation-based and XML based configuration of actions coexists ?

Yes

12. What is struts.devMode and why it is used ?

struts.devMode is a key used in struts.properties file (Can also be configured in


struts.xml file as <constant name="struts.devMode" value="true" />) , to represent
whether the framework is running in development mode or production mode by
setting true or false. If set to development mode, it gives the following benefits : -

> Resource bundle reload on every request; i.e. all localization properties
file can be modified and the change will be reflected without restarting the
server.

> struts.xml or any configuration  files can be modified without restarting


or redeploying the application

> The error occurs in the application will be reported, as oppose to


production mode.

Also remember that struts.devMode should be marked as false in production


environment to reduce impact of performance. By default it is "false".

13. How do you configure the annotation based action mapping ?


14. What is the difference between empty default namespace and root name space ?

If the namespace attribute is not defined in the package tag or assigned "" value then
it is called empty default namespace.While if "/" is assigned as value to the
namespace attribute then it is called as root namespace.

The root namespace is treated as all other explicit namespaces and must be matched.
It’s important to distinguish between the empty default namespace, which can catch
all request patterns as long as the action name matches, and the root namespace,
which is an actual namespace that must be matched.

15. Which interceptor is responsible for setting action's JavaBean properties ?

com.opensymphony.xwork2.interceptor.ParametersInterceptor is the interceptor


class who sets the action's JavaBean properties from request.
16. What is the difference between Action and ActionSupport ?

Action is interface defines some string like SUCCESS,ERROR etc  and an execute()
method. For convenience Developer implement this interface to have access to
String field in action methods. ActionSupport on other hand implements Action and
some other interfaces and provides some feature like data validation and localized
error messaging  when extended in the action classes by developers. 

17. How do you get the HttpServletRequest object in an interceptor ?

Here is the intercept method

view source

print?

01.public String intercept(ActionInvocation invoke) throws Exception {

02. 

03.      ActionContext action=invoke.getInvocationContext();

04. 

05.      HttpServletRequest
req=(HttpServletRequest)action.get(StrutsStatics.HTTP_REQUEST);

06. 

07.      return null;

08. 

09.    }

In the similar way you can get the response, by using StrutsStatics.HTTP_RESPONSE in
get() method as above.

18.  What is execute and wait interceptor ?  


19.Difference between errortag and message tag »
Q) What is the difference between errorstag and message tag?
Rep) Errorstag genereates the error for Ex: <%@ taglib uri=”/tags/struts-html” prefix=”html” %>
O/P of rs.jsp </html:errors/> When the errors tag is evaluated a list of error message will be
generated based on the  ActionError objects available in ActionErrors object. while generating
the list of errors [...]

Q) What is the advantage of DispatchAction class? A) Using DispatchAction class you can
overcome writing one Action class for one business entity. Instead you can write multiple
business entities in one Action class and call the business  method that is required by the
application. Q) Can you write your own method in Action class [...]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy