Struts2 Interview Questions and Answers For Graduates Part-2
12.What is the purpose of plug-in tag in struct-config.xml?
This section tells Struts where to find your properties files, which contain prompts and error messages.
13.What is the purpose of struts.properties in Struct2?
This configuration file provides a mechanism to change the default behavior of the framework. Actually all of the properties contained within the struts.properties configuration file can also be configured in the web.xml using the init-param, as well using the constant tag in the struts.xml configuration file. But if you like to keep the things separate and more struts specific then you can create this file under the folder WEB-INF/classes. The values configured in this file will override the default values configured in default.properties which is contained in the struts2-core-x.y.z.jar distribution.
14.What are interceptors in Struts 2?
Interceptors are conceptually the same as servlet filters or the JDKs Proxy class. Interceptors allow for crosscutting functionality to be implemented separately from the action as well as the framework. You can achieve the following using interceptors −
Providing preprocessing logic before the action is called.
Providing postprocessing logic after the action is called.
Catching exceptions so that alternate processing can be performed.
15.How can you create your custom interceptor in Struts 2?
Creating a custom interceptor is easy; the interface that needs to be extended is the Interceptor interface.
16.How interceptor works in Struts 2?
Actual action will be executed using the interceptor by invocation.invoke() call. So you can do some pre-processing and some post-processing based on your requirement.
The framework itself starts the process by making the first call to the ActionInvocation object’s invoke(). Each time invoke() is called, ActionInvocation consults its state and executes whichever interceptor comes next. When all of the configured interceptors have been invoked, the invoke() method will cause the action itself to be executed.
17.What are Result types in Struts?
The Action class manages the application’s state, and the Result Type manages the view.
18.What is defeult result type?
Default result type is dispatcher, which is used to dispatch to JSP pages.
19.What is the purpose of dispatcher result type?
The dispatcher result type is the default type, and is used if no other result type is specified. It’s used to forward to a servlet, JSP, HTML page, and so on, on the server. It uses the RequestDispatcher.forward() method.
20.What is the purpose of redirect result type?
he redirect result type calls the standard response.sendRedirect() method, causing the browser to create a new request to the given location. We can provide the location either in the body of the <result…> element or as a <param name=”location”> element.