||Struts 1.x 2.x | Spring | Strips | Wicket | Tapestry | Seam | JSF | RIFE | DWR | DOJO | EXT | Jquery | Json | Prototype | Hibernate | iBatis | web 2.0 | www.siva2baba.com & shivababa@gmail.com
   
  FrameWorks Theater
  Struts 1.X & 2.x
 

Content


   -->Struts 1.x Life Cycle
           --> Action Types
   --->Struts 2.x Life Cycle
   --->Different between Struts 1.x Struts 2.x
   --->Developer Point of View Struts 1.x and Struts 2.x
   --->Step by step Develpement:
Struts 1.X -Example
   --->Step by step Develpement: Struts 2.X -Example
   --->
Example program --http://siva2baba.diinoweb.com

Struts 1.x life Cycle
             

           client  HTTP Request
                    ||   
                    ||  
               Action-servlet (web.xml)
                        ||
                        ||
                      Request Processor(process())
                                        ||
                                        ||
                               Action class(execute())
                                        ||
                                        ||
                                       Return Action Forward(struts.comfig.xml)
                                        ||
                                        ||
                             HTTP Response() to client
                       
Action Types:
1.Forward Action
2.Dispatch Action
3.include Action
4.lookUpDispatch Action:
5.MappingDispatch Action
6.switch Action
7.Locale Action

Dispatch Action:
It provides mechanism to  collect related functions into a single action and eliminates the need of creating multiple independent actions for each function.
Forward Action:
It enables to forward request to the specified URL.
Include Action:
It  provides mechanism to include the contents of a specified URL.
LookUpDispatch Action:
It  provides mechanism  to combine many similar actions into a single action class, in order to simplify the  application design .Java map class is used to dispatch methods.
MappingDispatch Action:
It lets you combine many related actions into a single action class and manage through  creating multiple action-mappings.
switch Action:
It provides a mechanism to switch between modules and  then forwards control to a URI (specified in a number of possible ways) within the new module.
Locale Action:
It  provides mechanism to set a user's locale and further forwarding that to a specified page.

Struts 1.x  + WebWork Framework = Struts 2

Struts 2.x Life Cycle

       web browser requests
                    ||
                    ||

                Filter Dispatcher
                    ||
                    ||

               Interceptors(to perform workflow, validation,
                                            and file upload handling)
                    ||
                    ||

                Action(The Action method executes, usually storing and/or
                              retrieving information from a database)
                    ||   
                    ||

                The Result renders the output to the browser, be it
                 HTML, images, PDF, or something else
   
Struts 1 Struts 2
Action Action
ActionForm Action POJO
ActionForward Result
Struts-config.xml struts.xml
RequestProcess Interceptors
ActionServlet FilterDispatcher
validation.xml Action-validation.xml



Step by step Develpement:
Struts 1.X -Example


    Struts 1.x Example

                exercise03
                    ||
                      WEB-INF
                          ||---> 
web.xml
                          ||--->
struts-config.xml
                          ||----->classesstrutsexample
                                           ||--->CustomerAction.java
                                           ||--->CustomerForm.java
                          ||---->lib
                       ||--->index.jsp
                       ||--->Success.jsp
                       ||---->CustomerForm.jsp






Step by step Develpement:
Struts 2.X -Example


             
Struts 2.X -Example
                                    ||
                                   
WEB-INF
                                           |---struts.xml

                                           |--------------->
classes
                                               |--->mypackage
                                                           |--->HomeTime.java
                                           |--------------->lib
                                                   |---------------->struts2-core-2.0.11.jar
                                                   |---------------->xwork-2.0.4.jar
                                                   |---------------->xml-apis-1.0.b2jar
                                                   |---------------->ognl-2.6.11.jar
                                                   |---------------->commons-beanutils-1.6.1.jar
                                                   |---------------->commons-digester-1.6.jar
                                                   |---------------->commons-lang-1.0.jar
                                                   |---------------->commons-codec-1.2.jar
                                                   |---------------->commons-collections-2.1.jar
                                           |---->Web.xml

                                    ||
                                    
index.jsp
                                    


Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Struts Helloworld</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>


    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>


index.jsp

<html>
    <head>
        <META HTTP-EQUIV="Refresh" CONTENT="0;URL=pages/HelloTime.action">
    </head>
   
    <body>
        <p>Loading ...</p>
    </body>
</html>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
   
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />
   
    <package name="mypackage" namespace="/pages" extends="struts-default">
       
        <action name="HelloTime" class="mypackage.HelloTime">
            <result>/pages/HelloTime.jsp</result>
        </action>
       
        <action name="*" class="mypackage.HelloTime">
            <result>/pages/HelloTime.jsp</result>
        </action>
       
        <!-- Add actions here -->
    </package>
   
</struts>

mypackage.HelloTime.java

/*
 * HelloTime.java
 *
 
* Created on Jan 18, 2008, 3:22:49 PM
 *
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mypackage;

/**
 *
 * @author 150883
 */
import com.opensymphony.xwork2.ActionSupport;
import java.util.Date;

public class HelloTime extends ActionSupport {
   
    public static final String MESSAGE = "My Own Struts 2 Hello Time Tutorial!";
   
    public String execute() throws Exception {
        setMessage(MESSAGE);
        return SUCCESS;
    }
   
    private String message;
   
    public void setMessage(String message){
        this.message = message;
    }
   
    public String getMessage() {
        return message;
    }
   
    public String getCurrentTime(){
        return new Date().toString();
    }
}

page/HelloTime.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
    <head>
        <title>Struts 2 Hello Time Application!</title>
    </head>
    <body>
        <h2><s:property value="message" /></h2>
        <p>Current date and time is: <b><s:property value="currentTime" /></b>
    </body>
</html>




 
  Today, there have been 3 visitors (6 hits) on this page! www.siva2baba.com & shivababa@gmail.com  
 
||Struts 1.x 2.x | Spring | Strips | Wicket | Tapestry | Seam | JSF | RIFE | DWR | DOJO | EXT | Jquery | Json | Prototype | Hibernate | iBatis | web 2.0 | http://siva2baba.diinoweb.com/files/ and www.siva2baba.com This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free