4 avg. rating (80% score) - 1 votes
Finding another job can be so cumbersome that it can turn into a job itself. If you are expertise in Java then prepare well for the job interviews to get your dream job. Here's our recommendation on the important things to need to prepare for the job interview to achieve your career goals in an easy way. Java Struts is the most popular framework for developing Java based web applications. Struts is being developed as an open source project started by Apache Software Foundation . Struts framework is based on Model View Controller (MVC) architecture. Developers use it for developing. Follow our Wisdomjobs page for Java Struts job interview questions and answers page to get through your job interview successfully in first attempt.
Struts framework is composed of following components:
1. Based on the Model-View-Controller (MVC) design paradigm, distinctly separating all three levels:
Model: application state
View: presentation of data (JSP, HTML)
Controller: routing of the application flow
2. A request handler provided by the application developer that is used to mapped to a particular URI.
3. A response handler which is used to transfer the control to another resource which will be responsible for completing the response.
4. A tag library which helps developers to create the interactive form based applications with server pages.
5. Java Servlets
6. JSP (Java Server Pages)
7. Custom Tags
8. Message Resources
The POJO class is light weight and easy to test with frameworks like Junit. Moreover, there is no need to create separate ActionForms as in struts one to hold the values from the source web page. It is done by a single POJO class in struts 2.
Controller uses a configuration file “struts-config.xml file to get all mapping information to decide which action to use for routing of user’s request.It work as the router in the network and process and map the request to the associated action or resource.
In Struts, Action Class acts as a controller and performs following key tasks:
1.After receiving user request, it processes the user’s request.
2.Uses appropriate model and pulls data from model (if required).
3.Selects proper view to show the response to the user.
Struts Validator Framework enables us to validate the data of both client side and server side.
There are two types of validation supported in the struts framework:-
1. Clint side validation (Using java script support and enabling java script in ur browser).
2. Server site validation (using Validator method or ActionServlet class and).
There is another way which is defining the rules of validation in validation-rule.xml file.
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:
1. Validator-Rules.xml file
2. Validation.xml file
In order to use Struts framework, we only need to add Struts.Jar file in our development environment. Once jar file is available in the CLASSPATH, we can use the framework and develop Strut based applications.
In Struts, action class provides two important methods which can be used to avoid duplicate form submissions.
saveToken() method of action class generates a unique token and saves it in the user’s session.isTokenValid() method is used then used to check uniqueness of tokens.
Bean Tag Library is a Struts library which can be used for accessing Java beans.
For JSP configuration details, Web.xml file is used.
In Validation.xml, we define validation rules for any specific Java bean while in validator-rules.xml file, standard and generic validation rules are defined.
Struts.xml file is one the key configuration files of Struts framework which is used to define mapping between URL and action. When a user’s request is received by the controller, controller uses mapping information from this file to select appropriate action class.
Use of logic tags in Struts helps in writing a clean and efficient code at presentation layer without use of scriptlets.
Action mapping contains all the deployment information for a particular Action bean. This class is to determine where the results of the Action will be sent once its processing is complete.
Struts is based on MVC and hence there is a good separation of different layers in Struts which makes Struts applications development and customization easy. Use of different configuration files makes Struts applications easily configurable. Also, Struts is open source and hence, cost effective.
In Struts framework, actionServlet acts as a controller and all the requests made by users are controlled by this controller. ActionServlet is based onsingleton design patter as only one object needs to be created for this controller class. Multiple threads are created later for each user request.
For validation of populated properties, validate() method of ActionForm class is used before handling the control of formbean to Action class.
Although Struts have large number of advantages associated, it also requires bigger learning curve and also reduces transparency in the development process.
Struts also lack proper documentation and for many of its components, users are unable to get proper online resources for help.
resourcebundle.properties file is used to define specific error messages in key value pairs for any possible errors that may occur in the code.
This approach helps to keep the code clean as developer doesn’t need to embed all error messages inside code.
Struts framework works on the concept of centralized control approach and the whole application is controlled by a single servlet controller. Hence, we require only one servlet controller in a servlet application.
Struts support all types of models including Java beans, EJB, CORBA. However, Struts doesn’t have any in-built support for any specific model and it’s the developer’s choice to opt for any model.
Yes Struts are thread safe. In Struts, a new servlet object is not required to handle each request; rather a new thread of action class object is used for each new request.
Resource files (.properties files) can be used in Struts by adding following configuration entry in struts-config.xml file:
Following are the core classes provided by Struts Framework:
Struts should be used when any or some of the following conditions are true:
1.A highly robust enterprise level application development is required.
2.A reusable, highly configurable application is required.
3.A loosely coupled, MVC based application is required with clear segregation of different layers.
Struts is based on model 2 MVC (Model-View-Controller) architecture. Struts controller uses the command design pattern and the action classes use the adapter design pattern. The process() method of the RequestProcessor uses the template method design pattern. Struts also implement the following J2EE design patterns.
1.Service to Worker
3.Composite View (Struts Tiles)
The different kinds of actions in Struts are:
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:
1.Global Action Specific Exception Handler Definition.
2.Local Action Specific Exception Handler Definition.
1.The DispatchAction enable the programmer to combine together related function or class.
2.Using Dispatch Action programmer can combine the user related action into a single UserAction. like add user, delete user and update user.
3.DispatchAction execute the action based on the parameter value it receives from the user.
1.The LookupDispatchAction class is a subclass of DispatchAction.
2.The LookupDispatchAction is used to call the actual method.
3.For using LookupDispatchAction, first we should generate a subclass with a set of methods.
4.It control the forwarding of the request to the best resource in its subclass.
5.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.
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.
Java Struts Related Tutorials
|J2EE Tutorial||Core Java Tutorial|
|Hibernate Tutorial||JavaServer Faces (JSF) Tutorial|
|Log4j Tutorial||Java XML Tutorial|
|NHibernate Tutorial||iBATIS Tutorial|
|Spring MVC Framework Tutorial|
Java Struts Related Interview Questions
|J2EE Interview Questions||Core Java Interview Questions|
|Hibernate Interview Questions||JavaServer Faces (JSF) Interview Questions|
|Log4j Interview Questions||Java Management Extensions (JMX) Interview Questions|
|Java XML Interview Questions||iReport Interview Questions|
|NHibernate Interview Questions||iBATIS Interview Questions|
|Spring MVC Framework Interview Questions||Apache Wicket Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.