Important Java Struts interview questions and answers.
1. What is Struts?
Struts is an open source software that helps developers to easily build web application. It is a web page development framework which comprises of Java Servlets, Java Server Pages, custom tags, and message resources into a single framework. It is also a cooperative platform for development teams as well as independent developers.
2. Explain the components of Struts?
Struts is based on the MVC design pattern and its components can be categorized into:
Model: Components like business logic / business processes and data are parts of this.
View: It contains JSP, HTML etc.
Controller: Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.
3. How will we make any Of the Message Resources Definitions file available to the Struts Framework Environment?
Message Resources Definitions file are simple property files which consists of messages that can be used in the struts applications. Message Resources Definitions files can also be added to the struts-config.xml file using <message-resources /> tag.
E.g. <message-resources parameter=”Message Resources” />
4. What is Struts Validator Framework?
Struts Framework provides the functionality to validate the form data. This can be used to validate data on both the client side as well as server side. It emits the java scripts and can be used to validate data on the user’s browser and incase of server side validation, it is done by sub classing the From Bean with DynaValidatorForm class.
The Validator framework comes integrated with the Struts Framework and can be used without doing any extra change in settings.
5. Is struts thread safe?
Struts is thread safe as well as thread-dependant. Light-weight Action object handles the response to a request instead of individual servlets. The Action class is instantiated only once and lets the other requests to be threaded through the original object available. This technique helps to provide the best possible throughput and conserves resources. A properly-designed application will exploit this further by routing related operations through a single Action.
6. What are the core classes of the Struts Framework?
The core classes of Struts framework are:
ActionServlet is the back bone of the whole web application.
ActionForm is a Java bean that associates one or more ActionMappings.
The business logic is wrapped by the Action class which provides an interface to the Model of the application.
ActionMapping is used to provide mappings for Objects to Actions.
ActionForward represent the destination for the controller.
Advanced Struts Interview questions and answers
7. What are the different kinds of actions in Struts?
The different kinds of actions in Struts are as follows:
a. ForwardAction.
b. IncludeAction.
c. DispatchAction.
d. LookupDispatchAction.
e. SwitchAction.
8. What is Action Class?
The Action Class is a part of the Model. Its purpose is to translate the HttpServletRequest to the business logic and use the Action, we need to have a Subclass and overwrite the execute() method, In which all the database/ business processing are done. The ActionServlet (command) passes the parameterized class to Action Form using the execute() method and its return type is used by the Struts Framework to forward the request to the file according the value of the returned ActionForward object.
9. What are the various Struts tag libraries?
The various Struts tag libraries are:
a. Bean tag library – to access JavaBeans and their properties.
b. HTML tag library – to give standard HTML output, like forms, text boxes, etc.
c. Logic tag library – in order to generate conditional output, iteration capabilities and flow management.
d. Tiles or Template tag library – for those application using tiles.
e. Nested tag library – in order to use the nested beans in the application.
10. How the exceptions are handled in struts?
Exceptions in Struts are handled in two ways:
a. Programmatic exception handling: It is the explicit try/catch blocks in the code that can throw exception. It works well when any error occurs in the custom value
b. Declarative exception handling: In this we either define <global-exceptions> handling tags in the struts-config.xml or exception handling tags within <action></action> tag. It works well when error occurs in custom page and applies only to exceptions thrown by Actions.
11. What are the contents of web.xml and struts-config.xml? Explain the difference between them.
The web.xml file contains the information used by servlets and JSPs, having the description of the application, mapping information about servlets and URL, JSP configuration information, error page information without the exceptions.
The struts-config.xml file contains information about struts framework at the time of deploying the web application. It includes information about form bean, action mappings, controller information containing the buffer size, content type, etc.
12. What is SwitchAction & ForwardAction in struts?
A SwitchAction switches between modules and forwards the control to the URL specified in the new module. There are two parameters namely page, to which control is forwarded after switching and prefix that specifies the module to which the control is switched.
A ForwardAction is used to forward a request to the specified URL, represented as a destination to the controller to which it is sent after the action is completed.
13. What is Struts Flow?
Struts Flow is a port of Cocoon’s Control Flow to Struts in order to allow complex workflow, like multi-form wizards, which is easily implemented using continuations-capable JavaScript. It provides the ability to describe the order of web pages that have to be sent to the client, at any given point of time in an application.
14. Why is ActionForm a base class rather than an interface?
Making ActionForm a class gives advantage of the single inheritance restriction of Java in order to make difficult for people to do things that they are not supposed to.
However, if ActionForm is implemented as interface encourages matching of property types to the underlying business tier, violating one of the important purpose of ActionForm and also encourages using of existing DAO objects which violates MVC design pattern.
struts interview questions and answers for experienced pdf struts interview questions and answers for experienced
GOOD
:-)
thanks for struts interview questions
great…questions.
Fabulous Q&A
thanks a lot..this is helpful for all java interviewee..
Nice interview questions some of them are asked on other interviews. see here for some more experienced struts interview questions .
Thanks
Nice questions, here are some from my collection of Struts interview questions answers you may like
http://javarevisited.blogspot.com/2011/11/struts-interview-questions-answer-j2ee.html
ssss
gfdsgfd
nice question and answer. this is very help fully to every java developer.