What are the components of Struts Framework?
Struts framework is comprised of following components:
·         Java Servlets
·         JSP (Java Server Pages)
·         Custom Tags
·         Message Resources
What’s the role of a handler in MVC based applications?
It’s the job of handlers to transfer the requests to appropriate models as they are bound to the model layer of MVC architecture. Handlers use mapping information from configuration files for request transfer.
What’s the flow of requests in Struts based applications?
Struts based applications use MVC design pattern. The flow of requests is as follows:
·         User interacts with View by clicking any link or by submitting any form.
·         Upon user’s interaction, the request is passed towards the controller.
·         Controller is responsible for passing the request to appropriate action.
·   Action is responsible for calling a function in Model which has all business logic implemented.
·     Response from the model layer is received back by the action which then passes it towards the view where user is able to see the response.
Which file is used by controller to get mapping information for request routing?
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.
How an action Form bean is created?
Surrogate
Action Form bean is created by extending the classorg.apache.struts.action.ActionForm
In the following example we have created an action Form bean with the name 'test Form':
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
public class testForm extends ActionForm {
private String Id=null;
private String State=null;
public void setId(String id){
this.Id=id;
}
public String getId(){
return this.Id;
}
public void setState(String state){
this.State=state;
}
public String getState(){
return this.State;
}
What are the two types of validations supported by Validator Frame Work?
Validator Framework is used for form data validation. This framework provides two types of validations:
·         Client Side validation on user’s browser
·         Server side validation
What are the steps of Struts Installation?
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.
What’s the role of Action Class in Struts?
In Struts, Action Class acts as a controller and performs following key tasks:
·         After receiving user request, it processes the user’s request.
·         Uses appropriate model and pulls data from model (if required).
·         Selects proper view to show the response to the user.
How can we group related actions in one group in Struts?
To group multiple related actions in one group, we can use Dispatcher Action class.
When should we use switch Action?
The best scenario to use Switch Action class is when we have a modular application with multiple modules working separately. Using Switch Action class we can switch from a resource in one module to another resource in some different module of the application.
What are the benefits of Struts framework?
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.
What steps are required to for an application migration from Struts1 to Struts2?
Following Steps are required for Struts1 to Struts2 migration:
·         Move Struts1 action Form to Struts2 POJO.
·         Convert Struts1 configuration file (struts-config.xml) to Struts2 configuration file (struts.xml)
How properties of a form are validated in Struts?
For validation of populated properties, validate() method of Action Form class is used before handling the control of form bean to Action class.
What’s the use of reset method of Action Form class?
reset method of action Form class is used to clear the values of a form before initiation of a new request.
What are disadvantages of Struts?
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.
What’s the use of resource bundle? properties file in Struts Validation framework?
Resource bundle. 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.
Can I have html form property without associated getter and setter form bean methods?
For each html form property, getter and setter methods in the form bean must be defined otherwise application results in an error.
How many servlet controllers are used in a Struts Application?
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.
For a single Struts application, can we have multiple struts-config.xml files?
We can have any number of Struts-config.xml files for a single application.
We need following configurations for this:
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/struts-config.xml
/WEB-INF/struts-config_user.xml
/WEB-INF/struts-config_admin.xml
</param-value>
</init-param>
.............
.............
</servlet>
Which model components are supported by Struts?
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.
When it’s useful to use Include Action?
 Include Action is action class provided by Struts which is useful when an integration is required between Struts and Servlet based application.
Is Struts thread safe?
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.
What configuration changes are required to use resource files in Struts?
Resource files (.properties files) can be used in Struts by adding following configuration entry in struts-config.xml file:
<message-resources parameter=”com.login.struts.ApplicationResources”/>
How nested beans can be used in Struts applications?
Struts provide a separate tag library (Nested Tag Library) for this purpose. Using this library, we can nest the beans in any Struts based application.
What are the Core classes of Struts Framework?
Following are the core classes provided by Struts Framework:
·         Action Class
·         Action Form Class
·         Action Mapping Class
·         Action Forward Class
·         Action Servlet Class
Can we handle exceptions in Struts programmatically?
Yes, we can handle exceptions in Struts programmatically by using try, catch blocks in the code.
try {
// Struts code
}
Catch (Exception e) {
// exception handling code
}
Is Struts Framework part of J2EE?
Although Struts framework is based on J2EE technologies like JSP, Java Beans, Servlets etc. but it’s not a part of J2EE standards.
How action mapping is configured in Struts?
Action mappings are configured in the configuration file struts-config.xml under the tag <action-mapping> as follows:
<pre><action-mappings>
<action path="/login"
type="login.loginAction"
name="loginForm"
input="/login.jsp"
scope="request"
validate="true">
<forward name="success" path="/index.jsp"/>
<forward name="failure" path="/login_error.jsp"/>
</action>
</action-mappings>
When should be opt for Struts Framework?
Struts should be used when any or some of the following conditions are true:
·         A highly robust enterprise level application development is required.
·         A reusable, highly configurable application is required.
·  A loosely coupled, MVC based application is required with clear segregation of different layers.
Why Action Servlet is singleton in Struts?
In Struts framework, action Servlet acts as a controller and all the requests made by users are controlled by this controller. Action Servlet is based on singleton design patter as only one object needs to be created for this controller class. Multiple threads are created later for each user request.
What are the steps required for setting up validator framework in Struts?
Following Steps are required to setup validator framework in Struts: –Wrong Spelling
In WEB-INF directory place valdator-rules.xml and validation.xml files.
Enable validation plug in in struts-config.xml files by adding following:
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
Which technologies can be used at View Layer in Struts?
In Struts, we can use any of the following technologies in view layer:
·         JSP
·         HTML
·         XML/XSLT
·         WML Files
·         Velocity Templates

·         Servlets
Request to Download PDF

Post A Comment:

0 comments: