Struts2 Interview Questions



1.What is a framework?
A framework is made up of the set of classes which allow us to use a library in a best possible way for a specific requirement.
2.What is Struts framework?
Struts framework is an open-source framework for developing the web applications in Java EE, based on MVC-2 architecture. It uses and extends the Java Servlet API. Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.
3.What are the components of Struts?
Struts components can be categorize into Model, View and Controller: Model: Components like business logic /business processes and data are the part of model. View: HTML, JSP are the view components.
Controller: Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.
4.What are the core classes of the Struts Framework?
Struts is a set of cooperating classes, servlets, and JSP tags that make up a reusable MVC 2 design. JavaBeans components for managing application state and behavior. Event-driven development (via listeners as in traditional GUI development). Pages that represent MVC-style views; pages reference view roots via the JSF component tree.
5.What is ActionServlet?
ActionServlet is a simple servlet which is the backbone of all Struts applications. It is the main Controller component that handles client requests and determines which Action will process each received request. It serves as an Action factory – creating specific Action classes based on user’s request.
6.What is role of ActionServlet?
ActionServlet performs the role of Controller: Process user requests Determine what the user is trying to achieve according to the request Pull data from the model (if necessary) to be given to the appropriate view, Select the proper view to respond to the user Delegates most of this grunt work to Action classes Is responsible for initialization and clean-up of resources
7.What is the ActionForm?
ActionForm is javabean which represents the form inputs containing the request parameters from the View referencing the Action bean.
8.What are the important methods of ActionForm?
The important methods of ActionForm are : validate() & reset().

Q: How to create an action with Struts2?
Ans: Creating an action in Struts2 is very different from Struts1 in the sense that there is no mandatory requirement to extend a class from the struts library.
A Java bean/POJO which has the private member variables and public getters and setters is sufficient to become a struts action class.
As far as execute() method of Struts1 is concerned, a method with return type of String is sufficient. The method name is to be specified in the struts.xml.
This change is done so that the testing of struts based application can be done easily.

Q: In struts.xml, what does the attribute "method" stands for in the "action" tag?
Ans: The method attribute tells the name of method to be invoked after setting the properties of the action class. This attribute can either hold the actual name of the method or the index of the result mapping.
For example:
/success.jsp /success.jsp

In both the examples, the method being invoked by Struts will be login with the signature as public String login()

1 comment: