Spring

Spring Projects

Spring Project 1

Spring Subjective Questions And Answers
More interview questions and answers

What is struts?

The Jakarta struts project, an open source project supported by the Apache software Foundation, is a server side java implementation of the model view controller (MVC) design pattern.
The struts framework designed to create Web application that easily separate the presentation layer and allow it to  be abstracted from the transaction and data layers.

What are the various steps involved in the implementaion of struts?

   The struts framework models its server side implementation of the MVC using a combination of JSPs, custom JSP tags, and a Java Servlet. It involves the following steps :

   The incoming request is received by the ActionServlet, which acts as the controller, and the ActionServlet looks up the requested URI in an XML file.
   The Action Class performs its logic on the Model components associated with the application.
Once the Action has completed its processing, it returns control to the ActionServlet with a key that indicates the result of its processing. ActionServlet uses this key to determine where this result should be forwarded for presentation.
   The request is complete when the ActionServlet response by forwarding the request ot the view that was linked to the returned key, and this view presents the result of the Action.

What is MVC design pattern?

MVC stands for Model-View-Controller. The MVC design pattern is originated from Smalltalk, consists of three components : a Model, a View, and a Controller.

  MODEL : Represents the data objects. The Model is what is being manipulated and presented to the user. Model contains the business logic of the application.

  VIEW : Serves as screen representation of the Model. It is the object that represents the current state of the objects.

  CONTROLLER : Defines the way the user interface reacts to the user\'s input. The Controller component is the object that manipulates the Model, or data object.

How will you install struts framework in your web application?

The following steps are involved to install struts framework in your web application :

  •     Uncompress the Struts Archive to your local disk.
  •     Create a new web Application say, MyStrutsApp inside the webapps directory under the tomcat directory.
  •     Copy all the jar files, extracted from the lib directory into the /webapps/MyStrutsApp/WEB-INF/lib directory.
  •     Create an empty web.xml file and copy it to the /webapps/MyStrutsApp/WEB-INF/ directory.
  •     Create an empty struts-config.xml file and copy it to the /webapps/MyStrutsApp/WEB-INF/ directory. The struts-config.xml file is the diployment descriptor for all Struts applicattion. It is the file that glues all of the MVCcomponents together.

Describe the struts specific form tag?

Instead of using the standard HTML Form tag, like most HTML pages, the struts specific Form tag is : 

<html:form action=\"\" name=\"\" type=\"\">
..........
</html:form>


This tag with its subordinate input tags, encapsulates Struts form processing. The Form tag attributes are :  
action : Represents the URL to which this form will be submitted. This is also used to find the appropriate ActionMapping in the Struts configuration file.  
name : Identifies the key that is used to lookup the appropriate ActionForm that will represent the submitted form data.  
type : Names the fully qualified classname of the form bean you want to use in this request.

To use the struts specific <html:form> tag you have to use the taglib directive:
<%@ taglib uri=\"WEB-INF/struts-html.tld\" prefix=\"html\" %>

What is ActionForm in the struts?

When an <html:form/> is submitted, the Struts framework populates the matching data members of the ActionForm with the values entered in the <html:form/> tag. The Struts framework does this by using JavaBean introspection. This is all done by the class specified in the type attribute of the <html:form/> tag. This class will extends the org.apache.struts.action.ActionForm, as must all ActionForm objects with a get and set accessor that match its data members.

What are the parameters used in the Action.execute() method in the Struts.

The following parameters are used in the Action.execute(...) method : 
  • ActionMapping : The <b>ActionMapping</b> class contains all of the deployment information for a particular Action object. This class is used to determine where the result of the class (that extends the Action class) will be sent once its processing is complete. 
  • ActionForm : Represents the form inputs containing the request parameters from the view referencing this Action bean.
  • HttpServletRequest : Reference to the current Http request object. 
  • HttpServletResponse : Reference to the current Http response object.

Which mathod is use to forward the result to the appropriate view in the Action class in Struts?

The findForward() method is use to forward the result to the appropriate view in the Action class. This method takes the parameter name for the view file to which the result is being forwarded.

How will you tell the web application and container about your ActionServlet?

This can be accomplished by adding the following servlet definition to the web.xml file :
<servelt>
  <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</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

Once you told the container about the ActionServlet you need to tell it when it should be executed by adding <servelt-mapping> element in web.xml file :

<servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>*.do</url-pattern>
</servlet-mapping>

This mapping tells the web application that whenever a request is received with .do appended to the URL then the servlet named action should service the request.

What are the various struts controller components?

Four distinct Struts Controller components:

  • The ActionServlet class
  • The Action class
  • Plugins
  • RequestProcesser

What is ActionServlet class in the struts controller?

The org.apache.struts.action.ActionServlet is the backbone of all Struts application. It is the main controller component that handles the client request and determines which org.apache.struts.action.Action will process each received request. It serves as an Action factory - creating specific Action classes based on the user\'s request.

What is the entry point to ActionServlet when a request comes in.

The two main entry point into the ActionServlet are the same as any other servlet : doGet() and doPost().
They call single method named process(). The struts specific behavior begin with this method.

What is the process() method doing in the ActionServlet class?

The process() method gets the current RequestProcessor and invokes the RequestProcessor.process() method.The RequestProcessor.process() method is where the current request is actually serviced. This method retrieves from the struts-config.xml file, the <action> element that matches the path submitted on the request. It does this by matching the path passed in the <html:form/> tag\'s action element to the <action> element with the same path value.

Who calls the ActionForm.validate() method inside the ActionServlet.

The RequestProcessor.process() method calls the ActionForm.validate() method, which checks the validity of the of the submitted values.

What is for Action.execute() method?

The execute method is where your application logic begins. It is the method that you need to override when defining your own Actions. The execute() method has two functions:

  * It performs the user-defined business logic associated with your application.
  * It tells the Framework where it should next route the request.

The Struts framework defines two execute() methods. The first execute() implementation is used when you are defining custom Actions that are not HTTP specific, i.e. anlogous to the javax.servlet.GenericServlet class. The second, HTTP specific, You need to override the Action.execute() method and is anlogous to the javax.servlet.HttpServlet class.
Its signature is:

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpResponse response) throws IOException, ServletException{// some code here}

Describe the purpose of the Action class?

The org.apache.struts.action.Action class is a most common component of the Struts Controller. This class must be extended for each specialized Struts function in your application. 

The collection of these Action classes is what defines your web application.

To develop your own Action class, you must complete the following steps:
Create a class that extends the org.apache.struts.action.Action class.
Implement the appropriate execute() method and add your specific business logic.
Compile the new Action and move it to the Web application\'s classpath, i.e. /WEB-INF/classes directory.
Add an <action> element to the application\'s struts-config.xml file describing the new Action.

What are Struts Plugins?

Struts Plugins are modular extensions to the Struts Controller. They are defined by the org.apache.struts.action.Plugin interface.  

Struts Plugins are useful when you are allocating resources or preparing connections to the databases or even JNDI resources.

This interface defines two life-cycle methods: init() and desstroy().

What are the steps involved in Struts Plugins?

All Plugins must implement the two Plugin methods init() and destroy(). To develop your own Plugin You must complete the following steps:

  1. Create a class that implements the org.apache.struts.action.Plugin interface.
  2. Add a default empty constructor to the Plugin implementation. You must have a default constructor to ensure that the ActionServlet property creates your Plugin.
  3. Implement both the init() and destroy() methods and your implementation.
  4. Compare the new Plugin and move it into the web applocation\'s classpath.
  5. Add a <plug-in> element to the application\'s struts-config.xml file describing the new Plugin.

What is RequestProcessor? How will you create your own RequestProcessor?

The RequestProcessor is the class that you need to override when you want to customize the processing of the ActionServlet. 

It contains a predefined entry point that is invoked by the Struts controller with each request. The entry point is the processPreprocess() method.

Steps involved in creation your own RequestProcessor:

  1. Create a class that extends the org.apache.struts.action.RequestProcessor class.
  2. Add a default empty constructor to the RequestProcessor implementation.
  3. Implement your processPreprocess() method.

How will you configure the Plugin in your web application.

To deploy and configure your Plugin class, you must:

  1. Compile and move the Plugin class file into your application\'s WEB-INF/classes/ directory.
  2. Add a <plug-in> element to your struts-config.xml file.
    For example
    <plug-in className=\"MyPlugin\"/>
    The <plug-in> element should be the last element in the struts-config.xml file.
  3.   Restart the Web application.

What are the advanced Action classes? Why do you need ForwardAction class?

Advanced Action classes are the built-in Action classes that come with the Struts. These are:
 
  1. ForwardAction
  2. IncludeAction
  3. DispatchAction
  4. LookupDispatchAction
  5. SwitchAction

ForwardAction: The ForwardAction acts as a bridge from the current view (JSP) and the pages it links to. It uses the RequestDispatcher to forward to a specified web resource. It is the glue that allows you to link to an action instead of directly to a JSP. It follow the two steps:

  1. Use the <html:link> tag with the action attribute, add a link to a JSP page that points to the action.
  2. Create an action mapping in the Struts configuration file that uses ForwardAction with the parameter attribute to specify the JSP path.

Which is better approach, forward attribute or ForwardAction in the Struts framework to forward the request to next view.?

The Struts configuration file includes support for both the forward attribute and ForwardAction.

The ForwardAction   

<action path=\"/home\" type=\"org.apache.struts.action.ForwardAction\" parameter=\"/index.jsp\">
The forward attribute:  

<action path=\"/home\" forward=\"/index.jsp\">
These two mappings are functionally equivalent. It is an easy decision to pick the one you should use, of course, the shorter one.

</action></action>

What is the difference between the ForwardAction and the IncludeAction in the Struts?

The main difference between the ForwardAction and the IncludeAction is that you need to use IncludeAction only if the action is going to be included by another action or JSP.

Therefore, if you have code in your JSP that looks like this:
  <jsp:include page=\"/someWebApp/someModule/someAction.do\"/>
The action could not use a ForwardAction because it would forward control to the new action rather than including its output within the output of the JSP, or throw a IlligalStateException if the output buffer is already committed.

Which class would you use to forward the group related actions and what are steps involved.

The DispatchAction class is used to forward the group related actions into one class. DispatchAction is an abstract class, so you must override it to use it. It extends the Action class.

Rather than having a single execute method, you have a method for each logical action. The DispatchAction dispatches to one of the logical actions represented by the method. It picks a method to invoke based on an incoming request parameter.

You should follow the following steps:
 
  1. Create an action handler class that subclasses DispatchAction.
  2. Create a method to represent each logical related action.
  3. Create an action mapping for this action handler using the parameter attribute to specify the request parameter that carries the name of the method you want ot invoke.
  4. Pass the action a request parameter that refers to the method you want to invoke.

What are the two input tags of the tags?

The <html:form/> tag serves as the container for all other Struts HTML input tags. It acts as a parent to two other HTML tags:

The <html:text/> tag:
This tag is equivalent to the HTML text input tag, with the only difference being the property attribute, which names a unique data member found in the ActionForm bean class named by the form\'s type attribute.

<html:text property=\"\" />
The <html:submit/> tag:
This tag simply emulates an HTML Submit button by submitting the request to the targeted action.

What are the ActionForm Bean objects in Struts?

The org.apache.struts.action.ActionForm objects are JavaBeans that are used to encapsulate and validate the request data submitted by an HTTP request. 

All of the ActionForm must extends the org.apache.struts.action.ActionForm.

It contains setters and getters methods. The setters method are called by The Struts framework when a request is submitted with a parameter matching a data member\'s name.

What is the alternatice approach to the ActionForm in Struts?

You have to develop a new ActionForm object for just about every piece of business logic, i.e. for every Action object. This process is time consuming and irritating.

Struts solve this problem by introducing of a dynamic ActionForm, called the DynaActionForm. It gives the developer the ability to define a Form object using an XML entry in the struts-config.xml file.

What is an ActionMapping?

An ActionMapping object describes an Action instance to the ActionServlet. It represents the information that uniquely defines an instance of a particular action class. 

The values defined by an ActionMapping object are what make a particular <action> definition unique.

The ActionMapping object also provides useful information to the Action.execute() method, giving an Action object the ability to alter its behavior based on the values describing a particular ActionMapping instance. The signature of the Action.execute() method:

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){//some code here}

How will you create your own ActionMapping?

To create your own ActionMapping extension, you have to perform the following steps:

  1. Create a class that extends the org.apache.struts.action.ActionMapping class.
  2. Define the additional properties that will be used to describe your Action objects.
  3. Call the super() method, which calls the ActionMapping\'s default constructor at the beginning of your action mapping\'s constructor.
  4. Define matching setters and getters that can be used to modify and retrieve the values of the defined properties.

What are the extensions of the ActionMapping provided by the struts?

The struts framework provides two extended ActionMapping classes:   

org.apache.struts.action.SessionActionMapping
org.apache.struts.action.RequestActionMapping

What are the two i18n components of a Struts Application?

The tow main components packaged with the Struts framework for internationalization of your Struts application are:

  1. Message class that references a resource bundle containing Locale-dependent string and managed by the application Controller.
  2. JSP custom tag, <bean-message/>, which is used in the view layer to present the actual string managed by the Controller.

Give name of the error management classes provided by the Struts framework?

The Struts framework provides two error management classes:
 
  1. ActionError
  2. ActionErrors

What is the difference between the ActionError and ActionErrors class provided by the Struts Framework?

The org.apache.struts.action.ActionErrorclass extends the org.apache.struts.action.ActionMessageclass and represents the single error message. 

The key attribute of the ActionError class is used to lookup a resource from the application resource bundle, \"Internationalizing your struts application\".

The org.apache.struts.action.ActionErrorsclass extends the org.apache.struts.action.ActionMessage class and represents a collection of ActionError classes.

The ActionErrors class is composed of two constructors and a single method that allows you to add an ActionError object to the current collection of ActionErrors.

What is for tag provided by Struts specific JSP tag library.

The <html:errors/> tag is used to display the ActionError objects stored in ActionErrors collection.

What is the tiles framework in struts?

The tiles framework turns the concept of jsp:includes inside out. Developers can build pages by assembling reusable Tiles. You can think of Tiles as visual components. 

A Tile and a Tile layout can be reused on more than one page. Tiles are other JSP pages or any web resource. Tile layouts dictate how the Tiles will be laid out on the page.

How will you create a Tile layout view in your struts application?

To create a Tile layout, you must do the following:

  1.  Import the Tiles taglib into the JSP by using taglib directive.
  2.  Use string parameters to display such elements as the title of the page using the tiles:getAsStringTag.
  3.  Insert the Tiles in the correct regions of the layout using the tiles:insert tag.
  4.  Pass any needed parameters to the internal Tiles using the sub-tag of tiles:insert called tiles:put.

How will you use the Tile layout in your struts application?

To use a Tile, You need to perform the following steps:

  1. Import the Tiles taglib with the taglib directive.
  2. Use tiles:insert tag to insert the Tile layout into the current page.
  3. Use tile:put tag to pass string parameters.
  4. Use tiles:put tag to pass parameter Tiles.

How will you create the the JSP Tile definition?

Definitions specify default parameters for Tile layouts. You can create definitions in JSP or XML. 

To create a JSP Tile Definition, follow the following steps:

  1. Import the Tiles tag library using the taglib directive.
  2. Ensure that the definition is created only once using the logic:notPresent tag.
  3. Define the definition with the tiles:definition tag and pass the JSP that defines the Tile layout and the scope of the newly created definition.
  4. Define the default parameters with the tiles:put tag.

How will you use the the JSP Tile definition in your struts application?

To use a Tile definition, follow these steps:

  1. Import the Tiles taglib with taglib directive.
  2. Include the JSP page that creates the definition by using jsp:include.
  3. Use the tiles:insert tag, but specify the definition bean name and scope instead of the Tile layout page.
  4. Use the tiles:put attribute to specify the title and content but not header and footer parameters.

Describe the scope of the Tile in the Struts application?

The Tiles framework defines an additional scope called Tile scope. Like page scope, Tile scope is more private than request scope. It allows the user of the Tile to pass arguments (called parameters) to the Tile. Like a display function, it makes the page callable.

Nested tiles do not share the same Tile scope as their parent. The Tile scope of the current Tile is saved before the nested Tile is displayed; after the nested Tile finishes, the parent\'s Tile scope is restored to the request.

What is the difference between the jsp:include tag and tiles:insert tag?

The jsp:include tag allows you to call a page and pass it to request parameters (jsp:param); the tiles:insert tag is similar but more powerful. The tiles:insert allows you to call a page and pass it sub-pages (called Tiles) and attributes. Tile scope lets you pass variables that are available only to that Tile layout. 

What is the difference between tiles:importAttribute and tiles:useAttribute tag in the Tiles framework?

The tiles:importAttribute tag imports all of the attributes in Tile scope into page scope. It is similar to the tiles:useAttribute tag. It is lazy, dirty and cheap.

What is Tile controllers? How will you create your own Tile Controllers?

If you are putting too much java code into your Tile layout, or you have to put the same Java code into every Action that forwards to a page that uses a particular Tile layout, then you should use the Tile Controller.
The Controller class is similar to an Action.

You can map model objects into scope so that the Tile can display the items. To write a Tile Controller, follow these steps:
  1.   Create a class that implements org.apache.struts.tiles.Controller.
  2.   Implement the perform method.
  3.   In the perform method, do something with the model and map the results into scope so that Tile can use it.

Explain some of the Struts sub elements?

The sub-elements available to the top-level Struts components are:

The <icon/> Sub-Element: The <icon> sub-element contains <small-icon> and <large-icon> sub-elements that can be used to graphically represents its parent element in a Struts development tool.
      <icon>
         <small-icon>
          path to some graphics file
         <small-icon/>
         <large-icon>
          path to some graphics file
         <large-icon/>
      <icon/>

The <display-name/> Sub-Element: The <display-name> sub-element contains a short text description of its parent element for use in a Struts development tool.
    <display-name>
     short text description of its parent element.
    <display-name/>

The <descrition/> Sub-Element: The <description> sub-elementcontains a full length text description of its parent element for use in a Struts development tool.

    <descrition>
     full lenfth text description of its parent element.
<descrition/>

The <set-property/> Sub-Element: You can use the <set-property> sub element to set the value of additional JavaBean properties of objects describe by the <set-property> sub-element\'s parenet.
   
<set-property property=\"name of bean property\" value=\"value of bean property\"/>

How can you add a DataSource in your struts-config file?

The first component that we configure is a DataSource.
  <data-sources>        
     <data-source>         
         <set-property property=\"driverClass\" value=\"com.mysql.jdbc.Driver\"/>         
         <set-property property=\"url\" value=\"jdbc:mysql://localhost:3306/mydb\"/>
         <set-property property=\"user\" value=\"root\" />   
         <set-property property=\"password\" value=\"password\" />      
     </data-source>
  </data-sources>

How will you add FormBean Definitions in your struts configuration file?

The <form-bean> sub-element is used to describe an instance of a FormBean that is later bound to an Action.

<form-bean>
<form-bean name=\"unique bean name\" type=\"fully qualified class name\">
</form-bean>

How you can add the Global exception in your configuration file?

The <global-exception> sub-element is used to define n-number of <exception> sub-elements that are throwable by any Action in a Struts application. 

This sub-element acts as a container for all public <exception> sub-element.
The <exception sub-element> is used to associate a global exception with an ExceptionHandler.

The following declaration in struts-config.xml:

<global-exceptions>
    <exception
      key=\"qams.exception\"
      type=\"java.lang.Exception\"
      handler=\"com.qas.exceptions.QAMSExceptionHandler\"/>
</global-exceptions>

What are the various attributes of an sub-element in struts config file?

The attribute of an <exception> sub-element:
 
bundle  : A ServletContext attribute that names the resource bundle associated with the ExceptionHandler handling the defined <exception> elements.

className : The fully qualified class name of the configuration bean associated with the defined handler.

handler : The fully qualified class name of the ExceptionHandler that will process the contained <exception> sub-element.
 
key : Used to retrieve the message template associated with this exception.
 
path : The module-relative path that will act as the target of the ExceptionHandler associated with this exception.

scope : The scope of the ActionError object coupled with this exception(optional).
 
type : The fully qualified class name of the exception defined by this <exception> sub-element.(required).

What is Global forwards and define its attributes in struts config file?

The <global-forwards> sub-elements used to define n-number of <forward> sub-elements that are available to any Action in the Struts Application. It acts as a container for public <forward> sub-elements.

You can use <forward> sub-elements to describe a mapping of a logical name to a context relative URL path. A forward is used to identify the target of an Action class when it returns its result.

The attributes of a <forward> sub element:

name : Contains the unique identifier identifying this target.

path :
Specifies the Context relative path of the targeted resource.(required)

redirect :
If set to true, causes the ActionServlet to use the HttpServletResponse.sendRedirect() method, as opposed to RequestDispatcher.forward() method, when sending the Action results to the targeted resource. The default value is false.(optional)

What is for sub elements in struts config file?

The <action-mapping> sub-element is used to define n-number of <action> sub-elements. It acts as a container for <action> sub-elements.

The <action> sub-element is used to describe an Action instance to the ActionServlet.

<action-mappings>
        <action
            path=\"/logon\"
            type=\"org.apache.struts.webapp.example.LogonAction\"
            name=\"logonForm\"
            scope=\"request\"
            input=\"/logon.jsp\"
            unknown=\"false\"
            validate=\"true\" />
    </action-mappings>

Describe the attributes of sub-element?

The attributes of <action> Sub-Element:

path : Represents the context-relative path of the submitted request.

type : Specifies the fully qualified class name of the Action class being described by this ActionMapping.

name : Identifies the name of the form bean, if any, that is coupled with Action being defined.

scope : Specifies the scope of the form bean that is bound to the desired Action. The default value is session.

input : Represents the context-relative path of the input form to which control should be returned if a validation error is encountered.

className : Specifies the fully qualified class name of the ActionMapping implementation class you want to use in when invoking this Action class.

forward : Represents the context-relative path of the servlet or JSP resource that will process this request.

include : Represents the context relative path of the servlet or JSP resource that will process this request. This attribute is used if you do not want an Action to service the request to this path.

What is for element used in the struts config file?

The <controller> element is used to define a ControllerConfig bean (org.apache.struts.config.ControllerConfig) that represents an application\'s run-time module configuration.
The attributes of <controller> sub-element: bufferSize, className, contentType, inputForward, locale, maxFileSize, minFileSize, multipartClass, nocache, processorClass, tempDir.

Syntax:
<controller processorClass=\"MyRequestProcessor\" nocache=\"true\" />

How will you add a message Resource in your struts config file?

The <message-resources> element is used to describe a MessageResources object for the containing application. 

Syntax:
<message-resources parameter=\"configuration parameter\" key=\"main\" />


The attribute of a <message-resources> Element: className, factory, key, null, parameter.

How will you configure Plugins in your struts configuration file?

The <plug-in> element is used to add Plugins to the Struts Controller. Struts Plugins are useful when allocating resources or preparing connections to databases or even JNDI resources. The <plug-in> element has a single attribute, className, which is used to define the fully qualified Plugin class.
Syntax:
<plug-in className=\"Fully qualified plugin class name\" />

What are the steps involved in installing the HTML tag library in your Struts application?

To use HTML tag library in web application, You must complete the following steps:

Copy the TLD file packaged with this tag library struts-html.tld) to the webapps/MyAppName/WEB-INF directory.
Make sure that the struts.jar file is in the webapps/MyAppName/WEB-INF/lib directory.
Add the following <taglib> sub-element to the web.xml file of the Web application:
 
<taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
  </taglib>

You must add the following taglib directive to each JSP that will leverage the HTML tag library:
  <%@ taglib uri=\"/WEB-INF/struts-html.tld\" prefix=\"html\" %>

What is for tag in the HTML tag library defined in the Struts.

The <html:base/> tag is used to insert an HTML <base> element, including an href pointing to the absolute location of the hosting JSP page. 

This tag allows you to use relative URL references, rather than a URL that is relative to the most recent requested resource.

The <html:base/> tag has no body and supports two attributes:
target : Represents the target attribute of the HTML <base> tag (optional)
server : Identifies a server name to use in the href as opposed to the result of a call to request.getServerName() (optional)

Describe the attributes of the tag in the HTML tag library defined in the Struts.

The <html:button/> tag is used to render an HTML <input> element with an input type of button. The <html:button/> tag has a body type of JSP and supports the following attributes:  

property : Identifies the name of the input field being processed. (required)  
accessKey : Identifies a keyboard character to be used to immediately move focus to the HTML element defined by using this tag.  
alt : Defines an alternate text string for this element.  
altKey : Defines a resource key (to be retrieved from a resource bundle) that references an alternate text string for this element.  
disabled : If set to true, causes this HTML input element to be disabled. The default values is false.  
indexed : If set to true, then the name of the HTML tag is rendered as propertyName[indesNumber]. The indexed attribute is valid only when the tag is using it is nested with a <logic:itereate/> tag.
Other attributes are:
onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, style, styleClass, styleId, tabindex, title, titleKey, value.

How many types of tag libraries are available in the Struts framework?

Five types of tag libraries are available in the Struts framework:
 
HTML tag library.
Tiles tag library.
Logic tag library.
Template tag library.
Bean tag library.

What is for tag in HTML tag library in the Struts framework?

The <html:cancel /> tag is used to render an HTML <input> element with an input type of cancel. 

The <html:cancel /> has a body type of JSP and support the 25 attributes:

accessKey, alt, altKey, disabled, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, property, style, styleClass, styleId, tabindex, title, titleKey, value.

What is for tag in HTML tag library in the Struts framework?

The <html:checkbox/> tag is used to render an HTML <input> element with an input type of checkbox. 

The <html:checkbox/> has a body type of JSP and supports 27 attribute:

indexed, name, accessKey, alt, altKey, disabled, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, property, style, styleClass, styleId, tabindex, title, titleKey, value.


what is for tag in the HTML tag library? Define its attributes?

The <html:errors /> tag is used to display the ActionError objects stored in an ActionErrors collection. The <html:errors /> tag has a body type of JSP and support four attributes:
 
bundle : Specifies a MessageResources key of the resource bundle defined in the struts-config <message-resource> element.

locale : Specifies the session attribute containing the locale instance of the current. This locale is then used to select Locale-specific text messages.

name : Specifies the name of the request scope object that references the ActionErrors collection being displayed.

property : Specifies which error message should be displayed, based on each property contained in the ActionErrors collection.

what is the use of tag? Name all the attributes of this tag?

The <html:file/> tag is used to create an HTML <file> element. This tag allows you to upload files that will be populated in named ActionForm\'s identified property. 

The <html:file/> tag has a body of JSP and supports 30 attributes:

indexed, name, accessKey, alt, altKey, disabled, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, property, style, styleClass, styleId, tabindex, title, titleKey, value, accept, maxlength, size.


what is the use of tag? Name all the attributes of this tag?

The <html:form/> tag is used to create an HTML form. The form implicitly interacts with the named ActionForm bean to pre-populate the input fields values with the matching data members of the named bean. 

The <html:form/> tag has a body type of JSP and supports 13 attributes:
action, enctype, focus, focusIndex, method, onreset, onsubmit, scope, style, styleClass, styleId, target, type.

What is for tag defined in the HTML tag library in struts framework?

The <html:html/> tag is used to render the top-level <html> element. The <html:html/> tag has a body type of JSP and supports two attributes:

locale :
If set to true, then the Locale object named by the HTTP Accept-Language header is used to set the language preefrences.

xhtml : If set to true, causes an xml:lang attribute to be rendered as an attribute of the generated <html> element.

What is the difference between and tag in the HTML tag library in struts framework?

The <html:image/> tag is used to render an HTML <input> element with an input type of image. The image URL generated for this image is calculated using the value identified by the src or page attributes. You must specify one of the src or page attributes. 

The <html:image/> has a body type of JSP.
The <html:img/> tag is used to render an HTML <img> element. The image URL generated for this image is calculated using the value identified by the src or page attributes. You must specify one of the src or page attributes. The <html:img/> has no body.

What is the use of tag in the HTML tag library?

The <html:javascript/> tag is used to insert JavaScript validation methods based on the Commons Validator Plugin. The JavaScript methods used for validation are retrieved from the validator definition file using the formName as the index. 

The <html:javascript/> tag has no body and supports eight attributes:
cdata, dynamicJavaScript, formName, htmlComment, method, page, src, staticJavascript.

What is the use of tag in HTML tag library used in Struts application?

The <html:message/> tag is used to display a collection of messages stored in an ActionErrors, ActionMessages, String, or String array object. 

The <html:message/> has a body type of JSP and supports eight attributes:
id, bundle, locale, name, property, header, footer, message.

What is the difference between and tag in HTML tag library?

The <html:option/> tag is used to generate an HTML <input> element to type <option>, which represents a single option element nested inside a parent <select> element. 

The <html:option/> tag has a body type of JSP and supports eight attributes:
value, bundle, disabled, key, locale, style, styleId, styleClass.

The <html:options/> tag (as a child of the <html:select/> tag) is used to generate a list of HTML <option> elements. The <html:options/> tag has no body and support eight attributes:
collection, filter, labelName, lableProperty, name, property, style, styleClass.

What is for tag used defined by the HTML tag library?

The <html:rewrite/> tag is used to create a request URI based on the identical policies used with the <html:link/> tag but without the <a> element. 

The <html:rewrite/> tag has no body and supports 12 attributes:
anchor, forward, href, name, page, paramId, paramName, paramProperty, paramScope, property, scope, transaction.

What are the steps involved in installing the Tiles tag library in your Struts application?

To use Tiles tag library in web application, You must complete the following steps:

Copy the TLD file packaged with this tag library struts-tiles.tld to the webapps/MyAppName/WEB-INF directory.
Make sure that the struts.jar file is in the webapps/MyAppName/WEB-INF/lib directory.
Add the following <taglib> sub-element to the web.xml file of the Web application.

  <taglib>
    <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
  </taglib>


You must add the following taglib directive to each JSP that will leverage the Tiles tag library:
  <%@ taglib uri=\"/WEB-INF/struts-tiles.tld\" prefix=\"tiles\" %>

What is the use of tag in Tiles tag library in Struts framewrok?

The <tiles:insert/> tag is used to insert a Tiles template into a JSP. You must use the <tiles:put/> or <tiles:putList/> tags to substitute sub-components of the tile being inserted. 

The <tiles:insert/> tag has a body type of JSP and support 14 attributes:
template, components, page, definition, attribute, name, beanName, beanProperty, beanScope, flush, ignore, role, controllerUrl, controllerClass.

What is the use of tag in Tiles tag library in Struts framewrok?

The <tiles:definition/> tag is used to create a JavaBean representation of Tiles template definition that is stored in the named scope bound to the identifier named by id attribute. 

The <tiles:definition/> tag acts much like a runtime counterpart to the XML <definition/> found in the Tiles definition file.
The <tiles:definition/> tag has a body type of JSP and supports six attribute:
id, scope, template, page, role, extends.

What is for tag used in Tiles tag library in Struts framewrok?

The <tiles:put/> tag is used to define the equivalent of a parameter, representing a sub-component of a template, that will be used to the Tiles object. 

The <tiles:put/> tag has a body type of JSP and supports eight attribute:
name, value, direct, type, beanName, beanProperty, beanScope, role.

What is the use of tag in Tiles tag library in Struts framewrok?

The <tiles:putList/> tag is used to define a list of parameters that will passed as attribute to the Tiles object. The list is created from a collection of child <tiles:add/> tags. 

The <tiles:putList/> tag has a body type of JSP and supports a single attribute:
name : The name of the list being created.(Required)

What is the use of and tags in Tiles tag library in Struts framewrok?

The <tiles:add/> tag is used to add parameters to a parameter as defined by a <tiles:putList/> tag. 

The <tiles:add/> tag has a body type of JSP and supports seven attributes:
beanName, beanProperty, beanScope, direct, role, type, value.

The <tiles:get/> tag is used to retrieve and insert parameters previously defined from the Tiles context. With the exception of ignore attribute being defaulted to true, this tag is functionally the same as the <tiles:insert/>.

The <tiles:get/> tag has no body content and support four attributes:
name, ignore, flush, role.

Describe the and tags in Tiles tag library in Struts framewrok?

The <tiles:useAttribute/> tag is used to retrieve a Tiles object from the Tiles context and expose that object as a scriptlet variable. 

The <tiles:useAttribute/> tag has no body and supports five attribute:
name, id, className, scope, ignore.

The <tile:importAttribute/> tag is use to import a Tiles object from the Tiles context into a JSP scriptlet variable, which is stored in the named scope. If the name and scope attributes are not included are not included in the tag instance, then all Tile objects stored in the Tiles context are imported and placed in page scope.

The <tiles:importAttribute/> tag has no body and supports three attributes:
name, scope, ignore.

Which tag can be used to initialize the Tiles definition factory in Struts framework?

The <tiles:initComponentDefintions/> tag is used to initialize the Tiles definition factory. This tag is evaluated only once or not at all if the factory has already been initialized by other means. 

The <tiles:initComponentDefinition/> has no body and supports two attributes:

file : The file containing your Tile definitions.(Required)
classname : The fully qualified classname of the definition factory being initialized. This class, if specified, must implement the org.apache.struts.tiles.DefinitionFactory.(Optional)

What are the steps involved in installing the Logic tag library in your Struts application?

To use the Logic tag library in web application, You must complete the following steps:

  1. Copy the TLD file packaged with this tag library struts-logic.tld) to the webapps/MyAppName/WEB-INF directory.
  2. Make sure that the struts.jar file is in the webapps/MyAppName/WEB-INF/lib directory.
  3. Add the following <taglib> sub-element to the web.xml file of the Web application:

<taglib>
    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
  </taglib>


You must add the following taglib directive to each JSP that will leverage the HTML tag library:
  <%@ taglib uri=\"/WEB-INF/struts-logic.tld\" prefix=\"logic\" %>

What is the use of and tag defined by Logic tag library in Struts framework?

The <logic:empty/> tag evaluates its body if either the scripting variable identified by the name attribute or a property of the named scripting variable is equal to null or an empty string. 

The <logic:empty/> tag has a body type of JSP and supports three attributes:

name : Identifies the scripting variable being tested.
property : Identifies the data member of the scripting variable to be tested.(optional)
scope : Defines the scope of the bean specified by the name attribute.

The <logic:notEmpty/> tag evaluates its body if either the scripting variable or property of the named scripting variable is not equal to null or an empty string. The <logic:empty/> tag has a body type of JSP and supports three attributes:

name : Specifies a scripting variable to be used as the variable being tested.(Required)
property : Specifies the data member of the scripting variable to be tested.(optional)
scope : Defines the scope of the bean specified by the name attribute.

What is the use of and tag defined by Logic tag library in Struts framework?

The <logic:equal/> tag evaluates its body if the variable specified by any one of the attributes cookie, header, name, property, parameter equals the constant value specified by the value attribute. 

The <logic:equal/> tag has a body of JSP and supports seven attributes:
value, cookie, header, name, property, parameter, scope.

Example:

<logic:equal name=\"user\"
  property=\"age\"
  value=\"<%= requiredAge %>\">
  You are exactly at the right age.
</logic:equal>


The <logic:notEqual/> tag evaluates its body if the variable specified by any one of the attributes cookie, header, name, property, parameter is not equal to the constant value specified by the value attribute.

The <logic:equal/> tag has a body of JSP and supports seven attributes:
value, cookie, header, name, property, parameter, scope.

Example:

<logic:notEqual name=\"user\"
  property=\"age\"
  value=\"<%= requiredAge %>\">
  You are not at the right age.
</logic:equal>

What is the use of tag defined by Logic tag library in Struts framework? Describe its attribute?

The <logic:redirect/> tag uses the HttpServletResponse.sendRedirect() method to redirect the current request to a resource identified by either the forward, href, or page attributes. 

The <logic:redirect/> tag has no body and supports 12 attributes:

  * anchor : Used to append an HTML anchor to the end of a generated resource.
  * forward : Identifies the name of a global forward element that will receive control of the forwarded request.
  * href : Specifies the URL of the resource to forward the current request to.
  * name : Identifies a scripting variable referencing a java.util.Map object whose collection of key/value pairs is used as HTTP request parameters augmenting the redirected request.
  * property : Identifies a bean property of the bean named by the named attribute.
  * scope : Defines the scope of the bean specified by the name attribute.
  * transaction : If set to true, indicates that the current transaction control token should be included in the generated URL.
  * page : Specifies a context-relative path to a resource that will receive control of the current request.
  * paramId : Identifies the name of the request parameter that will be added to the generated URL.
  * paramName : Specifies a JSP scripting variable, containing a String reference, that represents the value for the request parameter  named by the paramId attribute.
  * paramProperty : Identifies a bean propertyof the bean named by paramName attribute.
  * paramScope : Specifies the scope of the bean specified by the paramName attribute.

What is the use of and tag defined by Logic tag library in Struts framework?

The <logic:greaterEqual/> tag evaluates its body if the variable specified by any one of the attributes cookie, header, name, parameter, or property is greater than or equal to the constant value specified by the value attribute. 

The <logic:greaterEqual/> tag has a body type of JSP and supports seven attributes:
value, cookie, header, name, property, parameter, scope.

The <logic:greaterThan/> tag evaluates its body if the variable specified by any one of the attributes cookie, header, name, parameter, or property is greater than the constant value specified by the value attribute.

The <logic:greaterThan/> tag has a body type of JSP and supports seven attributes:
value, cookie, header, name, property, parameter, scope.

What is the use of tag defined by Logic tag library in Struts framework? Name its attribute?

The <logic:iterate/> tag is used to iterate over a named collection - which contains a Collection, Enumerator, Iterator, Map, or Array - and evaluates its body for each Object in the collection. 

We can identify the collection being iterated over by using a request - time expression or a scripting variable.

The <logic:iterate/> tag has a body type of JSP and supports nine attributes:
id, collection, name, property, scope, type, indexId, length, offset.

What is the use of and tag defined by Logic tag library in Struts framework?

The <logic:lessEqual/> tag evaluates its body if the variable specified by any one of the attributes cookie, header, name, parameter, or property, is less than or equal to the constant value specified by the value attribute. 


The <logic:lessEqual/> tag has a body type of JSP and supports seven attributes:
value, cookie, header, name, property, parameter, scope.

The <logic:lessThan/> tag evaluates its body if the variable specified by any one of the attributes cookie, header, name, parameter, or property, is less than the constant value specified by the value attribute.

The <logic:lessThan/> tag has a body type of JSP and supports seven attributes:
value, cookie, header, name, property, parameter, scope.

What is the use of and tag defined by Logic tag library in Struts framework?

The <logic:match/> tag evaluates its body if the variable specified by any one of the attributes cookie, header, name, parameter, or property attributes contains the specified contant value. 

The <logic:match/> tag has a body type of JSP and supports eight attributes:
value, location, cookie, header, name, property, parameter, scope.

The <logic:notMatch/> tag evaluates its body if the variable specified by any one of the attributes cookie, header, name, parameter, or property does not contain the specified content value attribute. The <logic:notMatch/> tag has a body type of JSP and supports eight attributes:
value, location, cookie, header, name, property, parameter, scope.

What is the use of and tag defined by Logic tag library in Struts framework?

The <logic:present/> tag evaluates its body if the variable specified by any one of the cookie, header, name, parameter, or property attributes is present in the applicable scope. 

The <logic:present/> tag has a body type of JSP and supports eight attributes:
cookie, header, name, property, parameter, scope, role, user.

The <logic:notPresent/> tag evaluates its body if the variable specified by any one of the cookie, header, name, parameter, or property attributes is not present in the applicable scope.

The <logic:notPresent/> tag has a body type of JSP and supports eight attributes:
cookie, header, name, property, parameter, scope, role, user.

What are the steps involved in installing the Template tag library in your Struts application?

To use Template tag library in web application, You must complete the following steps:
Copy the TLD file packaged with this tag library, struts-template.tld, to the webapps/MyAppName/WEB-INF directory.
 Make sure that the struts.jar file is in the webapps/MyAppName/WEB-INF/lib directory.
 Add the following <taglib> sub-element to the web.xml file of the Web application:
 
</taglib>
<taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-template.tld</taglib-location>
  </taglib>


You must add the following taglib directive to each JSP that will leverage the HTML tag library:
  <%@ taglib uri=\"/WEB-INF/struts-template.tld\" prefix=\"template\" %>

What is the use of and tag defined by Template tag library in Struts framework?

The <template:get/> tag is used to retrieve the contents of a bean stored in the request scope, with the intention of replacing the tag instance with the contents of the retrieved bean. It is used to define the actual template JSP that will be referenced by the <template:insert/> tag. The bean being retrieved is assumed to have been placed on the request by a <template:put/> tag. 

The <template:get/> tag has no body and supports three attributes:
 name : Identifies the name of the request attributes to be retrieved. The name attribute should match the name of name attribute of the <template:put/> tag.(Required)
role : Specifies the role in which the user must exist for this tag to be evaluated.
 If set to true, results in the flushing of the response buffer prior to the inclusion of the specified request attribute.

The <template:put/> tag is used to store the content of a particular URL or text (URI or text) into the request scope. This tag is the parent to one or more put tags.

The put tags specify the content to be inserted into the template. The layout the content is determined by get tags placed in the template. The <template:put/> tag has no body and supports four attribute:
name : Identifies the name of the attribute to be stored in the request.
role : Specifies the role in which the user must exists for this tag to be evaluated.
content : Specifies the content that will be stored in the request.
direct : If set to true, indicates that the content attribute or body is printed to the request.

What is the use of tag defined by Template tag library in Struts framework?

The <template:insert/> tag is used to retrieve and insert the contents of the named URI. The <template:insert/> tag acts as the parent to one or more <template:put/>  tags, which act as parameters to the named template JSP. 

The <template:insert/> tag has a body type of JSP and a single required attribute template that names the URI of the resource to include as the template.

  <%@ taglib uri=\"/WEB-INF/tlds/struts-template.tld\" prefix=\"template\" %>
    <template:insert template=\"MyTemplate.jsp\" >
      <template:put name=\"navbar\" conten=\"/navbar.jsp\" />
      <template:put name=\"header\" conten=\"/header.jsp\" />
      <template:put name=\"body\" conten=\"/body.jsp\" />
      <template:put name=\"footer\" conten=\"/footer.jsp\" />
</template:insert>

What are the steps involved in installing the Bean tag library in your Struts application?

To use Bean tag library in web application, You must complete the following steps:
 
Copy the TLD file packaged with this tag library, struts-bean.tld, to the webapps/MyAppName/WEB-INF directory.
Make sure that the struts.jar file is in the webapps/MyAppName/WEB-INF/lib directory.
Add the following <taglib> sub-element to the web.xml file of the Web application:
 
<taglib>
    <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
  </taglib>


You must add the following taglib directive to each JSP that will leverage the HTML tag library:
  <%@ taglib uri=\"/WEB-INF/struts-bean.tld\" prefix=\"bean\" %>

What is the use of tag defined by Bean tag library in Struts framework?

The <bean:cookie/> tag is used to retrieve the value of an HTTP cookie. It can be used to retrieve single or multiple cookie values. The retrieved cookie(s) are stored in a page scoped attribute of type Cookie. 

If the named cookie is not found and no default value is specified, then a request-time exception is thrown.


The <bean:cookie/> tag has no body and supports four attributes:
id, name, multiple, value.

What is the use of tag defined by Bean tag library in Struts framework? Name all of its attribute?

The <bean:define/> tag is used to retrieve the value of a named bean property and define it as a scripting variable, which is will be stored in the scope specified by the toScope attribute. 

The retrieved object will perform type conversion on the returned property value, unless it is a Java primitive type, in which case it is wrapped in the appropriate wrapper class.


This <bean:define/> tag has a body type of JSP and supports seven attributes:
id, name, property, scope, toScope, type, value.

  <jsp:useBean
    id=\"user\"
    scope=\"page\"
    class=\"com.User\" />
  <bean:define
    id=\"user\"
    name=\"user\"
    property=\"firstName\" />
 
Welcome: <%= name%>

What is the use of tag defined by Bean tag library in Struts framework?

The <bean:header/> tag functions exactly like <bean:cookie/>, except that it retrieves its values from the named request header. Once the tag has the header values, it creates a java.lang.String or java.lang.String[] attribute and stores it in the pageContext.

If the named header cannot be located and no default value is given, then a request-time exception will be thrown. The <bean:header/> tag has a body type of JSP and supports four attributes:
id, name, multiple, value.

Example :
  <bean:header id=\"headerID\"
     name=\"Cache-control\"
     value=\"Cache-control not found\" />

What is the use of tag defined by Bean tag library in Struts framework?

The <bean:include/> tag is used to evaluate and retrieve the results of a web application resource. The tag makes the response data available as an object of type String.
The resource being evaluated by the <bean:include/> tag can be identified using three different attributes: forward, href, page.
The <bean:include/> tag has no body and supports six attributes:
id, achor, forward, href, page, transaction.

Example:
<bean:include id=\"navbar\" page=\"/navbar.jsp\" />

What is the use of tag defined by Bean tag library in Struts framework?

The <bean:message/> tag is a very useful tag that we can employ to retrieve keyed values from a previously defined resource bundle. It also supports the ability to include parameters that can be substituted for defined placeholders in the retrieved string. 

The <bean:message/> tag has no body and supports 11 attributes:
arg0, arg1, arg2, arg3, arg4, bundle, key, locale, name, property, scope.

Example:
<html>
  <head>
    <title><bean:message key=\"app.title\"/><title>
  <head>
  <body>
  ...
  </body>
</html>

What is the use of tag defined by Bean tag library in Struts framework?

The <bean:page/> tag is used to retrieve the value of an identified implicit JSP object, which it stores in the page context of the current JSP. 

The <bean:page/> tag has no body and supports two attributes: id and property.

Example

<bean:page id=\"sessionVar\" property=\"session\" />

What is the use of tag defined by Bean tag library in Struts framework?

The <bean:parameter/> tag is used to retrieve the value of a request paremeter identified by the name attribute. The retrieved value will be used to define a page scoped attribute to type java.lang.String or String[], if the multiple attribute is not null. 

The <bean:parameter/> tag has no body and supports four attributes:
id, name, multiple, value.

Example:
<bean:parameter id=\"userID\"  name=\"username\"  value=\"user found\" />

What is the use of tag defined by Bean tag library in Struts framework?

The <bean:resource/> tag is used to retrieve the value of Web application resource identified by the name attribute; the tag makes the resource available as either a java.io.InputStream or a java.lang.String object, based on the value of the input attribute. 

The <bean:resource/> tag has no body and supports three attributes: id, name, input.

What is the use of tag defined by Bean tag library in Struts framework?

The <bean:size/> tag is used to retrieve the number of elements contained in a reference to an array, collection, or map. 

The results of the <bean:size/> tag\'s evaluation is a scripting variable of type java.lang.Integer that contains the number of elements in that collection.
The <bean:size/> tag has no body and supports five attributes: id, collection, name, property and scope.

Example:

<bean:size id=\"count\" name=\"users\" />

What is the use of tag defined by Bean tag library in Struts framework?

The <bean:struts/> tag is used to copy a specified Struts internal component into a paged scoped scripting variable. The Struts components that can be retrieved include a FormBean, a forward, or mapping object. 

The <bean:struts/> tag has no body and supports four attributes:
id, formBean, forward, mapping.

Example:
<bean:struts id=\"userForm\"    formBean=\"UserForm\" />

What is the use of tag defined by Bean tag library in Struts framework?

The <bean:write/> tag is used to retrieve and print the value of a named bean property. If the format attribute is encountered, then the value being written will be formatted based upon the format string represented by the format attribute.
The <bean:write/> tag has no body and supports nine attributes:
bundle, filter, format, formatKey, ignore, locale, name, property, scope.

Example:
<bean:write name=\"employee\" property=\"username\" />

Why we use Struts framework in project?

Struts framework follow the Model-View-Controller design pattern. Struts framework provides the centralized control to throughout the Web application. If the application is big like any banking application etc, then you should use Struts as it is very robust, makes the things simple, it also has lot of readily available security features.

What is hierarchy of files in Struts?

The hierarchy of files depends upon struts-config.xml that plays an important role in struts framework and it is used mainly to have an access to various Action classes using the Action-mapping element and then to forward it to appropriate jsp files. The struts tag libraries include Bean tag, Template tag, Tiles tag, Logic tag, and HTML tag libraries.

why do we have only one ActionServlet in Struts?

The Struts Framework provides us the centralized control throughout the web application. We use the ActionServlet as a centralized controller. 

The ActionServlet takes care of all the request and direct it to the requested resourse. Using the more than controller doing the same thing leads to the duplicacy and redudndancy in your code. Hence there is no need to use more than one controller in a web application. That is why Struts uses the concept of a single Servlet controller.

What is the difference between Struts 1.x and Struts 2.x

The difference between Struts 1.x and Struts 2.x:

  * Struts 1.x extends the abstract base class by its action class. The problem with struts1 is that it uses the abstract classes rather than interfaces. While in Struts 2.x, an Action class implements an Action interface, along with other interfaces use optional and custom services.
  * Struts 1.x Actions are singletons therefore they must be thread-safe because only one instance of a class handles all the requests for that Action. Struts 2.x doesn\'t have thread-safety issues as Action objects are instantiated for each request. A servlet container generates many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.
  * In Struts 1.x Actions are dependent on the servlet API because HttpServletRequest and HttpServletResponse is passed to the execute method when an Action is invoked. Container does not treat the Struts 2 Actions as a couple. Servlet contexts are typically represented as simple Maps that allow Actions to be tested in isolation. Struts 2 Actions can still access the original request and response, if required.
  * Struts 1 binds objects into the page context by using the standard JSP mechanism. Struts 2 uses a ValueStack technology to make the values accessible to the taglibs without coupling the view to the object to which it is rendering.

Why was perform() method changed as execute() method in Action class?

The Action.perform() is the method called by the ActionServlet defined in Struts 1.x and declares that it throws only IOException and ServletException. To support declarative exception handling, the method\'s signature changed in perform() and it becomes the execute() method in the Struts 2.x. This is typically where your business logic resides.

What will happen if the mapping to actionform in the struts-config.xml is mentioned wrong?

An exception will be thrown. If we try to cast the action form and using it, then it will throw null-pointer exception.

How can we communicate from struts to ejb?

The ActionClass overrides execute() method.

Then in body of execute() method:

  1. Get Initial Context
  2. Get home object using JNDI look up.
  3. Create the bean and call the business methods.

What are the core classes of Struts?

The core classes of Struts are:
 
  1. Action,
  2. ActionForm,
  3. ActionServlet,
  4. ActionMapping,
  5. ActionForward, etc.

Is Action class is Servlet or Not ? if yes why ?

Action class extents org.apache.struts.action.Action which has nothing to do with Servlet. Its a plain java class which is been called/Managed by a well defined framework called Struts.

What is difference between Html tags and Struts specific HTML Tags

Struts tags bind the property value with the Formbean property defined. HTML tags are static and Struts tags are dynamic.

What are the contents of web.xml and struts-config.xml? What is the difference between them? How to relate these tow xml files?

A web.xml file is the DD (deployment descriptor) for any web based application while struts-config.xml is for specifically struts based application. 

A web.xml file establishes connection between application and container whereas struts-config.xml bridges gap between view and controller.

A web.xml file is read by container when we start the container. struts-config.xml file is used by init() method of ActionServlet.

Should every html form property have a corresponding formbean get/set and variable.?

Yes! Every html form property must have a corresponding FormBean get/set methods. Otherwise you\'ll get an error.

Can I have more than one struts-config.xml file for a single Struts application?

Yes! One can have more than one struts-config.xml file for a single Struts application. 

You can define different struts-conifg.xml file for different modules in a single web application. It is useful when you are developing a distributed application.

But you must enter those struts-config.xml files details in deployment descriptor (i.e., web.xml) file.

Example:
<init-param>
<param-name> config</param-name>
<param-value>/WEB-INF/struts-first-config.xml,/WEB-INF/struts-second-config.xml,/WEB-INF/struts-third-config.xml</param-value>
</init-param>


Here three struts configuration files are deployed in a single application.

How the container will know this is a struts application?

The web container do not need to know about the design pattern we used in our application. Our Struts application is deployed in the web.xml file. The container reads the web.xml file, and acts accordingly.

What is the super class of Action and ActionForm?

There is no immediate super class for Action and Action Form, Object class is the super class for Action and ActionForm.

What is the difference between Apache struts and Jakarta Struts? why there are 2 names?

Both Apache struts and Jakarta struts are one and the same. Struts was originally created by Craig McClanahan and was donated to the Apache Foundation in May, 2000. Its evolve as a Jakarta Project, in early 2004 it become an official Apache Project.

Explain about token feature in Struts?

The problem of duplicate form submission arises when a user clicks the Submit button more than once before the response is sent back. This may result in inconsistent transactions and must be avoided.

In Struts this problem can be handled by using the saveToken() and isTokenValid() methods of Action class. saveToken() method creates a token (a unique string) and saves that in the user\'s current session, while isTokenValid() checks if the token stored in the user\'s current session is the same as that was passed as the request parameter.

What is the purpose of tiles-def.xml file, resourcebundle.properties file, validation.xml file?

A tiles-def.xml is used as a configuration file for an appliction during tiles development. You can define the layout, header, footer, body content for your View.
The validation.xml file is used to declare sets of validations that should be applied to Form Beans. Each Form Bean you want to validate has its own definition in this file. Inside that definition, you specify the validations you want to apply to the Form Bean\'s fields.
Instead of having hard-coded error messages in the framework, Struts Validator allows you to specify a key to a message in the ApplicationResources.properties (or resourcebundle.properties) file that should be returned if a validation fails.

How you will save the data across different pages for a particular client request using Struts?

You can use the session object to save the data across different pages for a particular client request using Struts.
Create an appropriate instance of ActionForm that is form bean and store that form bean in session scope. So that it is available to all the pages that for a part of the request.

request.getSession()
session.setAttribute()

What are the disadvantages of struts?

Disadvantages of Struts:
  * Bigger Learning Curve. To use MVC with Struts, you have to be comfortable with the standard JSP and servlet APIs and a large and elaborate framework that is almost equal in size to the core system.
  * Worse Documentation. Compared to the standard servlet and JSP APIs, Struts has fewer online resources, and many first-time users find the online Apache documentation confusing and poorly organized.
  * Less Transparent. Struts applications are: Harder to understand and Harder to benchmark and optimize.
  * Rigid Approach. The flip side of the benefit that Struts encourages a consistent approach to MVC is that Struts makes it difficult to use other approaches.

How can we work struts on Eclipse? What is the best plugin for this?

Eclipse provides <add struts capabilities> option to any web project. Building struts application
becomes very easy with the GUI provided and drag drop feature of struts-config file. The best plug-in available for this is My-eclipse.

What are the JSTL and JavaServer Faces ?

JSTL, the JavaServer Standard Tag Library, is a set of JSP tags that are designed to make it easier to develop Web applications. JavaServer Faces (JSF) is a specification for a new technology that promises to make it easier to write MVC applications, both for the Web and for the desktop. Both JSTL and JSF are complementary to Struts. 

Can I have an Action without a form?

Yes! If your Action does not need any data and it does not need to make any data available to the view or controller component that it forwards to, it doesn\'t need a form. 

A good example of an Action with no ActionForm is the LogoffAction in the struts example application.

Describe the details of XML files used in the �Validator Framework�?

The Validator Framework uses two XML configuration files:

  * validator-rules.xml and
  * validation.xml.

The validator-rules.xml defines the standard validation routines. These are reusable and used in validation.xml to define the form specific validations.

The validation.xml defines the validations applied to a form bean.

How you will make available any Message Resources Definitions file to the Struts Framework Environment?

Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources definitions files can be added to the struts-config.xml file using the <message-resources />  tag.

Example:
<message-resources parameter=\"MessageResources\" />

What is LookupDispatchAction?

The LookupDispatchAction is an abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping.

Explain about the validation steps involved in validation of client side address?

The steps which are to be carried for validating client side address they are: 

  1. Validator plug in should be enabled to the system to start the process of validation.
  2. A message resource should be created which can display error message to the client.
  3. Validation rules should be defined by the developer for validation.
  4. Relevant tags should be created to generate Java script code.
  5. The whole process of validation should be tested.

How you will enable front-end validation based on the xml in validation.xml?

The <html:javascript> tag to allow front-end validation based on the xml in validation.xml. 

For example the code:

<html:javascript formName=\"logonForm\" dynamicJavascript=\"true\" staticJavascript=\"true\" />

 generates the client side java script for the form logonForm as defined in the validation.xml file. The <html:javascript> when added in the jsp file generates the client site validation script.

Is Struts compatible with other Java technologies?

Yes. 

Struts is committed to supporting industry standards. Struts acts as an integrator of Java technologies so that they can be used in the \"real world\".