Wu Yuxiong - natural born flyweight JAVA EE enterprise application development Struts2Sping4Hibernate Integrated Development Study Notes: Configuration Action (2)

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <package name="lee" extends="struts-default">
        <! - Use of Action defined pattern string name, specifies all ending Action requests,
        LoginRegistAction are available to process, method attributes using { 1 },
        {The first string replaced by * 1} represents the pattern matching ->
        <action name="*Action" class="org.crazyit.app.action.LoginRegistAction"
            method="{1}">
            <! - definition of the mapping between physical and logical view View ->
            <result name="error">/WEB-INF/content/error.jsp</result>
            <result>/WEB-INF/content/welcome.jsp</result>
        </action>
        <action name="*">
            <result>/WEB-INF/content/{1}.jsp</result>
        </action>
    </package>
</struts>
package org.crazyit.app.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;
/**
 * Description:
 * <br/> website: <a href=" http://www.crazyit.org "> crazy Java league </a>
 * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * Author   YeekuHLee kongyeeku163com
 * @version  1.0
 */

public class LoginRegistAction
    extends ActionSupport
{
    // two member variables encapsulated user request parameter 
    Private String username;
     Private String password;
     // username setter and getter methods 
    public String the getUsername ()
    {
        return username;
    }
    public void setUsername(String username)
    {
        this.username = username;
    }
    // password getter and setter methods 
    public String getPassword ()
    {
        return password;
    }
    public void setPassword(String password)
    {
        this.password = password;
    }

    // register control logic Action included 
    public String REGIST () throws Exception
    {
        ActionContext.getContext().getSession()
            .put("user" , getUsername());
        addActionMessage ( "Congratulations," + getUsername () + " , you have successfully registered!" );
         return SUCCESS;
    }
    // login control logic Action included 
    public String the Login () throws Exception
    {
        if (getUsername().equals("crazyit.org")
            && getPassword().equals("leegang") )
        {
            ActionContext.getContext().getSession()
                .put("user" , getUsername());
            addActionMessage ( "Welcome," + getUsername () + " , you are already logged successfully!" );
             return SUCCESS;
        }
        return ERROR;
    }
}
<?xml version="1.0" encoding="GBK"?>
<project name="struts" basedir="." default="">
    <property name="dist" value="classes"/>
    <property name="src" value="src"/>
    
    <path id="classpath">
        <fileset dir="lib">
            <include name="*.jar"/>
        </fileset>
        <pathelement path="${dist}"/>
    </path>

    <target name="compile" description="Compile all source code">
        <delete dir="${dist}"/>
        <mkdir dir="${dist}"/>
        <copy todir="${dist}">
            <fileset dir="${src}">
                <exclude name="**/*.java"/>
            </fileset>        
        </copy>
        <javac destdir="classes" debug="true" includeantruntime="yes"
            deprecation="false" optimize="false" failonerror="true">
            <src path="${src}"/>
            <classpath refid="classpath"/>
        </javac>
    </target>

</project>
<?xml version="1.0" encoding="GBK"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
    <! - define the core of Filter Struts 2 ->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <! - let Struts core Filter 2 intercept all requests ->
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <package name="lee" extends="struts-default">
        <! - Use of Action defined pattern string name, specifies all ending Action requests,
        LoginRegistAction are available to process, method attributes using { 1 },
        {The first string replaced by * 1} represents the pattern matching ->
        <action name="*Action" class="org.crazyit.app.action.{1}Action">
            <! - definition of the mapping between physical and logical view View ->
            <result name="error">/WEB-INF/content/error.jsp</result>
            <result>/WEB-INF/content/welcome.jsp</result>
        </action>
        <action name="*">
            <result>/WEB-INF/content/{1}.jsp</result>
        </action>
    </package>
</struts>
<?xml version="1.0" encoding="GBK"?>
<project name="struts" basedir="." default="">
    <property name="dist" value="classes"/>
    <property name="src" value="src"/>
    
    <path id="classpath">
        <fileset dir="lib">
            <include name="*.jar"/>
        </fileset>
        <pathelement path="${dist}"/>
    </path>

    <target name="compile" description="Compile all source code">
        <delete dir="${dist}"/>
        <mkdir dir="${dist}"/>
        <copy todir="${dist}">
            <fileset dir="${src}">
                <exclude name="**/*.java"/>
            </fileset>        
        </copy>
        <javac destdir="classes" debug="true" includeantruntime="yes"
            deprecation="false" optimize="false" failonerror="true">
            <src path="${src}"/>
            <classpath refid="classpath"/>
        </javac>
    </target>

</project>
<?xml version="1.0" encoding="GBK"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
    <! - define the core of Filter Struts 2 ->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <! - let Struts core Filter 2 intercept all requests ->
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <package name="lee" extends="struts-default">
        <! - Use of Action defined pattern string name, specifies all ending Action requests,
        LoginRegistAction are available to process, method attributes using { 1 },
        {The first string replaced by * 1} represents the pattern matching ->
        <action name="*Action" class="org.crazyit.app.action.LoginRegistAction"
            method="{1}">
            <! - definition of the mapping between physical and logical view View ->
            <result name="error">/WEB-INF/content/error.jsp</result>
            <result>/WEB-INF/content/welcome.jsp</result>
        </action>
        <action name="*">
            <result>/WEB-INF/content/{1}.jsp</result>
        </action>
    </package>
</struts>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> Error Page </ title>
</head>
<body>
    Sorry, your login failed!
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> login page </ title>
</head>
<body>
<table width="300" align="center">
<form action="loginAction" method="post">
    <tr>
        <Td> Username: </ td>
        <td><input type="text" name="username"/></td>
    </tr>
    <tr>
        <td>密&nbsp;&nbsp;码:</td>
        <td><input type="text" name="password"/></td>
    </tr>
    <tr>
        <td><input type="submit" value="登录" 
            onclick="this.form.action='loginAction';"/></td>
        <td><input type="submit" value="注册"
            onclick="regist();"/></td>
    </tr>
</form>
<table>
<script type="text/javascript">
function regist()
{
    // get the page first form 
    targetForm document.forms = [0 ];
     // dynamically modified form's action 
    targetForm.action = "registAction" ;
}
</script>
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> success page </ title>
</head>
<body>
    <s:actionmessage/>
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> Error Page </ title>
</head>
<body>
    Sorry, your login failed!
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> login page </ title>
</head>
<body>
<table width="300" align="center">
<form action="LoginAction" method="post">
    <tr>
        <Td> Username: </ td>
        <td><input type="text" name="username"/></td>
    </tr>
    <tr>
        <td>密&nbsp;&nbsp;码:</td>
        <td><input type="text" name="password"/></td>
    </tr>
    <tr>
        <td><input type="submit" value="登录"
            onclick="this.form.action='LoginAction';"/></td>
        <td><input type="submit" value="注册"
            onclick="regist();"/></td>
    </tr>
</form>
<table>
<script type="text/javascript">
function regist()
{
    // get the page first form 
    targetForm document.forms = [0 ];
     // dynamically modified form's action 
    targetForm.action = "RegistAction" ;
}
</script>
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> success page </ title>
</head>
<body>
    <s:actionmessage/>
</body>
</html>
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <package name="lee" extends="struts-default">
        <! - Use of Action defined pattern string name, specifies all ending Action requests,
        LoginRegistAction are available to process, method attributes using { 1 },
        {The first string replaced by * 1} represents the pattern matching ->
        <action name="*Action" class="org.crazyit.app.action.{1}Action">
            <! - definition of the mapping between physical and logical view View ->
            <result name="error">/WEB-INF/content/error.jsp</result>
            <result>/WEB-INF/content/welcome.jsp</result>
        </action>
        <action name="*">
            <result>/WEB-INF/content/{1}.jsp</result>
        </action>
    </package>
</struts>
package org.crazyit.app.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;
/**
 * Description:
 * <br/> website: <a href=" http://www.crazyit.org "> crazy Java league </a>
 * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * Author   YeekuHLee kongyeeku163com
 * @version  1.0
 */

public class LoginAction
    extends ActionSupport
{
    // two member variables encapsulated user request parameter 
    Private String username;
     Private String password;
     // username setter and getter methods 
    public String the getUsername ()
    {
        return username;
    }
    public void setUsername(String username)
    {
        this.username = username;
    }
    // password getter and setter methods 
    public String getPassword ()
    {
        return password;
    }
    public void setPassword(String password)
    {
        this.password = password;
    }
    // login control logic Action included 
    public String the Execute () throws Exception
    {
        if (getUsername().equals("crazyit.org")
            && getPassword().equals("leegang") )
        {
            ActionContext.getContext().getSession()
                .put("user" , getUsername());
            addActionMessage ( "Welcome," + getUsername () + " , you are already logged successfully!" );
             return SUCCESS;
        }
        return ERROR;
    }
}
package org.crazyit.app.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;
/**
 * Description:
 * <br/> website: <a href=" http://www.crazyit.org "> crazy Java league </a>
 * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * Author   YeekuHLee kongyeeku163com
 * @version  1.0
 */

public class RegistAction
    extends ActionSupport
{
    // two member variables encapsulated user request parameter 
    Private String username;
     Private String password;
     // username setter and getter methods 
    public String the getUsername ()
    {
        return username;
    }
    public void setUsername(String username)
    {
        this.username = username;
    }
    // password getter and setter methods 
    public String getPassword ()
    {
        return password;
    }
    public void setPassword(String password)
    {
        this.password = password;
    }
    // register control logic Action included 
    public String the Execute () throws Exception
    {
        ActionContext.getContext().getSession()
            .put("user" , getUsername());
        addActionMessage ( "Congratulations," + getUsername () + " , you have successfully registered!" );
         return SUCCESS;
    }
}

 

Guess you like

Origin www.cnblogs.com/tszr/p/12364384.html