ABOUT
Struts
Craig McClanahan originally wrote the Struts framework, mostly while on his Memorial Day vacation in 2000! .
The Validator framework was developed by David Winterfeldt as third-party add-on to Struts
Differences between Model1 and Model2 Architecture
Model 1
Model 2
In Model 1, the client directly accesses JSP pages. In other words, user requests are handled directly by the JSP page.

The servlet container parses the JSP and executes the resulting Java servlet. The JSP contains code and tags to access the Model ( it can be JavaBeans or even direct database code ). The Model contains attributes for holding the HTTP request parameters from the query string. In addition it contains logic to connect to the middle tier or directly to the database using JDBC to get the additional data needed to display the page. The JSP is then rendered as HTML using the data in the Model JavaBeans.
The main difference between Model 1 and Model 2 is that in Model 2, a controller handles the user request instead of another JSP. The controller is implemented as a Servlet. The following steps are executed when the user submits the request

  1. The Controller Servlet handles the user’s request. (This means the hyperlink in the JSP should point to the controller servlet).
  2. The Controller Servlet then instantiates appropriate JavaBeans based on the request parameters (and optionally also based on session attributes).
  3. The Controller Servlet then by itself or through a controller helper communicates with the middle tier or directly to the database to fetch the required data.
  1. The Controller sets the resultant JavaBeans (either same or a new one) in one of the following contexts – request, session or application.
  1. The controller then dispatches the request to the next view based on the request URL.
  2. The View uses the resultant JavaBeans from Step 4 to display data. The sole function of the JSP in Model 2 architecture is to display the data from the JavaBeans set in the request, session or application scopes
Client
Client
About RequestDispatcher
A RequestDispatcher object can forward a client's request to a resource or include the resource itself in the response back to the client. A resource can be another servlet, or an HTML file, or a JSP file, etc.

You can also think of a RequestDispatcher object as a wrapper for the resource located at a given path that is supplied as an argument to the getRequestDispatcher method.
For constructing a RequestDispatcher object, you can use either the ServletRequest.getRequestDispatcher() method or the ServletContext.getRequestDispatcher() method. They both do the same thing,only difference is the first will take absolute path and the later a relative path
More about Struts
The class org.apache.struts.action.ActionServlet is the called the ActionServlet, this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.

The Action class is part of the controller. The purpose of Action Class is to translate the HttpServletRequest to the business logic. The ActionServlet passes the parameterized class to Action Form using the execute() method

Ex:
public class MyAction extends Action
{
  public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{
      return mapping.findForward("myAction");
  }
}

An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application
and the ActionForm object is automatically populated on the server side
with data entered from a form on the client side

Ex:

public class MyForm extends ActionForm {
{
  //inherited methods
  public ActionErrors validate(ActionMapping mapping,
       HttpServletRequest request) {
       // TODO Auto-generated method stub
       return null;
}

  public void reset(ActionMapping mapping, HttpServletRequest request) {
       // TODO Auto-generated method stub
}
}

Struts Validator Framework
Struts Framework provides the functionality to validate the form data.t can be use to validate the data on the users browser as well as on the server side.Struts Framework generates the java scripts and it can be used to validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class

The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml
the <html:javascript> tag is used to allow front-end validation based on the xml in validation.xml.
struts-config.xml
<init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>

<servlet>
   <servlet-name>action</servlet-name>
   <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>

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

<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
web.xml
Each Action element is represented in memory by an instance of the org.apache.struts.action.ActionMapping class . The ActionMapping object contains a path attribute that is matched against a portion of the URI of the incoming request.

<struts-config>
       <form-beans>
         <form-bean name="MyForm" type="com.darla.MyForm"/>
       </form-beans>
  <action-mappings>        
         <action
                path="/Welcome"
                forward="/pages/Welcome.jsp"/>
         <action
                path="/Logon"
                forward="/pages/Logon.jsp"/>
        <action>
               path= "/myrequest"
       type="com.darla.MyAction"
               scope="request"
               name="MyForm"
               validate="true"
               input="myjsp.jsp"
           <forward name="Success" path="/success.jsp" redirect="true"/>
           <forward name="Failure" path="/anotherjsp.jsp" redirect="true"/>
       </action>
    </action-mappings>
</struts-config>
The action forward mappings also can be specified in a global section, independent of any specific action mapping.
<global-forwards>
    <forward name="Success" path="/success.jsp" />
    <forward name="Failure" path="/anotherjsp.jsp" />
</global-forwards>

Versions of Struts and when they are released
Struts 1.3.8
10 Mar 2007
1.3.9
01 Aug 2007
2.1.2
26 May 2008
2.0.14 General Availability Release
24 November 2008
TAGS
Narendra Kumar Dantala
A J2EE Developer
Having a masters degree in Computational Science, working in Java, developed applications on different domains such as Finanical Services, B2B, Banking, Utility...