zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然轻量级JAVA EE企业应用开发Struts2Sping4Hibernate整合开发学习笔记:使用Struts2的国际化(1)

    <?xml version="1.0" encoding="GBK"?>
    <project name="java" basedir="." default="help">
        <property name="src" value="src"/>
        <property name="dest" value="classes"/>
    
        <path id="classpath">
            <fileset dir="lib">
                <include name="**/*.jar"/>
            </fileset>
            <pathelement path="${dest}"/>
        </path>
    
    
        <!-- 编译src目录下所有源代码 -->
        <target name="compile" description="Compile all source code">
            <delete dir="${dest}"/>
            <mkdir dir="${dest}"/>
            <copy todir="${dest}">
                <fileset dir="${src}">
                    <exclude name="**/*.java"/>
                </fileset>        
            </copy>
            <javac destdir="${dest}" 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://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        version="3.0">
        <!-- 定义Struts 2的核心控制器:StrutsPrepareAndExecuteFilter -->
        <filter>
            <!-- 定义核心Filter的名字 -->
            <filter-name>struts2</filter-name>
            <!-- 定义核心Filter的实现类 -->
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
        <!-- StrutsPrepareAndExecuteFilter用来处理所有的HTTP请求 -->
        <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>
        <constant name="struts.i18n.encoding" value="GBK"/>
        <!-- 配置了一个包元素 -->
           <package name="lee" extends="struts-default">
            <action name="login" class="org.crazyit.app.action.LoginAction">
                <result name="input">/WEB-INF/content/loginForm.jsp</result>
                <result>/WEB-INF/content/result.jsp</result>
                <result name="error">/WEB-INF/content/result.jsp</result>
            </action>
            <action name="*">
                <result>/WEB-INF/content/{1}.jsp</result>
            </action>
        </package>
    </struts>
    #在JSP页面使用的JSP范围的资源文件
    loginPage=JSP消息:登录页面
    user=JSP消息:用户名
    pass=JSP消息:密  码
    login=JSP消息:登录
    #在JSP页面使用的JSP范围的资源文件
    loginPage=JSP Message:Login Page
    user=JSP Message:User Name
    pass=JSP Message:User Pass
    login=JSP Message:Login
    #u5728JSPu9875u9762u4f7fu7528u7684JSPu8303u56f4u7684u8d44u6e90u6587u4ef6
    loginPage=JSPu6d88u606fuff1au767bu5f55u9875u9762
    errorPage=JSPu6d88u606fuff1au9519u8befu9875u9762
    succPage=JSPu6d88u606fuff1au6210u529fu9875u9762
    failTip=JSPu6d88u606fuff1au5168u5c40u6d88u606fuff1au5bf9u4e0du8d77uff0cu60a8u4e0du80fdu767bu5f55uff01
    succTip=JSPu6d88u606fuff1au5168u5c40u6d88u606fuff1au6b22u8fceuff0cu60a8u5df2u7ecfu767bu5f55uff01
    user=JSPu6d88u606fuff1au7528u6237u540d
    pass=JSPu6d88u606fuff1au5bc6  u7801
    login=JSPu6d88u606fuff1au767bu5f55
    resultPage=登录结果
    resultPage=Log In Result
    resultPage=u767bu5f55u7ed3u679c
    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    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>
    <!-- 加载baseName为viewResources包下的baseName为loginForm的国际化资源文件 -->
    <s:i18n name="viewResources.loginForm">
    <html>
    <head>
        <meta name="author" content="Yeeku.H.Lee(CrazyIt.org)" />
        <meta http-equiv="Content-Type" content="text/html; charset=GBK" />
        <!-- 使用text标签来输出国际化消息 -->
        <title><s:text name="loginPage"/></title>
    </head>
    <body>
        <s:form action="login">
            <!-- 表单标签中使用key属性来输出国际化消息 -->
            <s:textfield name="username" key="user"/>
            <s:textfield name="password" key="pass"/>
            <s:submit key="login"/>
        </s:form>
    </body>
    </html>
    </s:i18n>
    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    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>
    <s:i18n name="viewResources.result">
    <html>
    <head>
        <meta name="author" content="Yeeku.H.Lee(CrazyIt.org)" />
        <meta http-equiv="Content-Type" content="text/html; charset=GBK" />
        <title><s:text name="resultPage"/></title>
    </head>
    <body>
        ${requestScope.tip}
    </body>
    </html>
    </s:i18n>
    <?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>
        <constant name="struts.i18n.encoding" value="GBK"/>
        <!-- 配置了一个包元素 -->
           <package name="lee" extends="struts-default">
            <action name="login" class="org.crazyit.app.action.LoginAction">
                <result name="input">/WEB-INF/content/loginForm.jsp</result>
                <result>/WEB-INF/content/result.jsp</result>
                <result name="error">/WEB-INF/content/result.jsp</result>
            </action>
            <action name="*">
                <result>/WEB-INF/content/{1}.jsp</result>
            </action>
        </package>
    </struts>
    package org.crazyit.app.action;
    
    import com.opensymphony.xwork2.*;
    
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    public class LoginAction extends ActionSupport
    {
        // 下面定义了两个成员变量,用于封装请求参数
        private String username;
        private String password;
    
        // username的setter和getter方法
        public void setUsername(String username)
        {
            this.username = username;
        }
        public String getUsername()
        {
            return this.username;
        }
    
        // password的setter和getter方法
        public void setPassword(String password)
        {
            this.password = password;
        }
        public String getPassword()
        {
            return this.password;
        }
    
        // 处理用户请求的execute()方法
        public String execute() throws Exception
        {
            ActionContext ctx = ActionContext.getContext();
            if (getUsername().equals("crazyit.org")
                && getPassword().equals("leegang"))
            {
                ctx.getSession().put("user" , getUsername());
                // 获取国际化消息
                ctx.put("tip" , getText("succTip"));
                return SUCCESS;
            }
            // 获取国际化消息
            ctx.put("tip" , getText("failTip"));
            return ERROR;
        }
    }
    failTip=Action消息:对不起,您不能登录!
    succTip=Action消息:欢迎,您已经登录!
    username.required=Action消息:用户名是必需的!
    failTip=Action Scope:Sorry,You can't log in!
    succTip=Action Scope:welcome,you has logged in!
    username.required=Action Scope: User Name is required!
    failTip=Actionu6d88u606fuff1au5bf9u4e0du8d77uff0cu60a8u4e0du80fdu767bu5f55uff01
    succTip=Actionu6d88u606fuff1au6b22u8fceuff0cu60a8u5df2u7ecfu767bu5f55uff01
    username.required=Actionu6d88u606fuff1au7528u6237u540du662fu5fc5u9700u7684uff01
    <?xml version="1.0" encoding="GBK"?>
    <!DOCTYPE validators PUBLIC
        "-//Apache Struts//XWork Validator 1.0.3//EN"
        "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
    <validators>
        <!-- 校验Action的name属性 -->
        <field name="username">
            <!-- 指定name属性必须满足必填规则 -->
            <field-validator type="requiredstring">
                <param name="trim">true</param>
                <message key="username.required"/>
            </field-validator>
        </field>
    </validators>
    #在JSP页面使用的JSP范围的资源文件
    loginPage=JSP Message:Login Page
    user=JSP Message:User Name
    pass=JSP Message:User Pass
    login=JSP Message:Login
    #u5728JSPu9875u9762u4f7fu7528u7684JSPu8303u56f4u7684u8d44u6e90u6587u4ef6
    loginPage=JSPu6d88u606fuff1au767bu5f55u9875u9762
    errorPage=JSPu6d88u606fuff1au9519u8befu9875u9762
    succPage=JSPu6d88u606fuff1au6210u529fu9875u9762
    failTip=JSPu6d88u606fuff1au5168u5c40u6d88u606fuff1au5bf9u4e0du8d77uff0cu60a8u4e0du80fdu767bu5f55uff01
    succTip=JSPu6d88u606fuff1au5168u5c40u6d88u606fuff1au6b22u8fceuff0cu60a8u5df2u7ecfu767bu5f55uff01
    user=JSPu6d88u606fuff1au7528u6237u540d
    pass=JSPu6d88u606fuff1au5bc6  u7801
    login=JSPu6d88u606fuff1au767bu5f55
    resultPage=登录结果
    resultPage=Log In Result
    resultPage=u767bu5f55u7ed3u679c
    #在JSP页面使用的JSP范围的资源文件
    loginPage=JSP消息:登录页面
    user=JSP消息:用户名
    pass=JSP消息:密  码
    login=JSP消息:登录
    <?xml version="1.0" encoding="GBK"?>
    <project name="java" basedir="." default="help">
        <property name="src" value="src"/>
        <property name="dest" value="classes"/>
    
        <path id="classpath">
            <fileset dir="lib">
                <include name="**/*.jar"/>
            </fileset>
            <pathelement path="${dest}"/>
        </path>
    
    
        <!-- 编译src目录下所有源代码 -->
        <target name="compile" description="Compile all source code">
            <delete dir="${dest}"/>
            <mkdir dir="${dest}"/>
            <copy todir="${dest}">
                <fileset dir="${src}">
                    <exclude name="**/*.java"/>
                </fileset>        
            </copy>
            <javac destdir="${dest}" 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://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        version="3.0">
        <!-- 定义Struts 2的核心控制器:StrutsPrepareAndExecuteFilter -->
        <filter>
            <!-- 定义核心Filter的名字 -->
            <filter-name>struts2</filter-name>
            <!-- 定义核心Filter的实现类 -->
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
        <!-- StrutsPrepareAndExecuteFilter用来处理所有的HTTP请求 -->
        <filter-mapping>
            <filter-name>struts2</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    </web-app>
    # 在JSP页面使用的JSP范围的资源文件
    loginPage=全局消息:登录页面
    user=全局消息:用户名
    pass=全局消息:密  码
    login=全局消息:登录
    resultPage=登录结果
    # 在Action中使用的国际化消息
    failTip=全局消息:对不起,您不能登录!
    succTip=全局消息:欢迎,您已经登录!
    # 在Action校验规则文件中使用的国际化消息
    username.required=全局消息:用户名是必需的!
    # 在JSP页面使用的JSP范围的资源文件
    loginPage=Global Message:Login Page
    user=Global Message:User Name
    pass=Global Message:User Pass
    login=Global Message:Login
    resultPage=Log In Result
    # 在Action中使用的国际化消息
    failTip=Global Scope:Sorry,You can't log in!
    succTip=Global Scope:welcome,you has logged in!
    # 在Action校验规则文件中使用的国际化消息
    username.required=Global Scope: User Name is required!
    #u5728JSPu9875u9762u4f7fu7528u7684JSPu8303u56f4u7684u8d44u6e90u6587u4ef6
    loginPage=u5168u5c40u6d88u606fuff1au767bu5f55u9875u9762
    user=u5168u5c40u6d88u606fuff1au7528u6237u540d
    pass=u5168u5c40u6d88u606fuff1au5bc6  u7801
    login=u5168u5c40u6d88u606fuff1au767bu5f55
    resultPage=u767bu5f55u7ed3u679c
    # u5728Actionu4e2du4f7fu7528u7684u56fdu9645u5316u6d88u606f
    failTip=u5168u5c40u6d88u606fuff1au5bf9u4e0du8d77uff0cu60a8u4e0du80fdu767bu5f55uff01
    succTip=u5168u5c40u6d88u606fuff1au6b22u8fceuff0cu60a8u5df2u7ecfu767bu5f55uff01
    # u5728Actionu6821u9a8cu89c4u5219u6587u4ef6u4e2du4f7fu7528u7684u56fdu9645u5316u6d88u606f
    username.required=u5168u5c40u6d88u606fuff1au7528u6237u540du662fu5fc5u9700u7684uff01
    <?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>
        <constant name="struts.i18n.encoding" value="GBK"/>
        <!-- 指定加载baseName为mess的国际化消息资源文件 -->
        <constant name="struts.custom.i18n.resources" value="mess"/>
        <!-- 配置了一个包元素 -->
           <package name="lee" extends="struts-default">
            <action name="login" class="org.crazyit.app.action.LoginAction">
                <result name="input">/WEB-INF/content/loginForm.jsp</result>
                <result>/WEB-INF/content/result.jsp</result>
                <result name="error">/WEB-INF/content/result.jsp</result>
            </action>
            <action name="*">
                <result>/WEB-INF/content/{1}.jsp</result>
            </action>
        </package>
    </struts>
    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    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>
    <html>
    <head>
        <meta name="author" content="Yeeku.H.Lee(CrazyIt.org)" />
        <meta http-equiv="Content-Type" content="text/html; charset=GBK" />
        <!-- 使用text标签来输出国际化消息 -->
        <title><s:text name="loginPage"/></title>
    </head>
    <body>
        <s:form action="login">
            <!-- 表单标签中使用key属性来输出国际化消息 -->
            <s:textfield name="username" key="user"/>
            <s:textfield name="password" key="pass"/>
            <s:submit key="login"/>
        </s:form>
    </body>
    </html>
    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    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>
    <s:i18n name="viewResources.result">
    <html>
    <head>
        <meta name="author" content="Yeeku.H.Lee(CrazyIt.org)" />
        <meta http-equiv="Content-Type" content="text/html; charset=GBK" />
        <title><s:text name="resultPage"/></title>
    </head>
    <body>
        ${requestScope.tip}
    </body>
    </html>
    </s:i18n>
    # 在JSP页面使用的JSP范围的资源文件
    loginPage=全局消息:登录页面
    user=全局消息:用户名
    pass=全局消息:密  码
    login=全局消息:登录
    resultPage=登录结果
    # 在Action中使用的国际化消息
    failTip=全局消息:对不起,您不能登录!
    succTip=全局消息:欢迎,您已经登录!
    # 在Action校验规则文件中使用的国际化消息
    username.required=全局消息:用户名是必需的!
    # 在JSP页面使用的JSP范围的资源文件
    loginPage=Global Message:Login Page
    user=Global Message:User Name
    pass=Global Message:User Pass
    login=Global Message:Login
    resultPage=Log In Result
    # 在Action中使用的国际化消息
    failTip=Global Scope:Sorry,You can't log in!
    succTip=Global Scope:welcome,you has logged in!
    # 在Action校验规则文件中使用的国际化消息
    username.required=Global Scope: User Name is required!
    #u5728JSPu9875u9762u4f7fu7528u7684JSPu8303u56f4u7684u8d44u6e90u6587u4ef6
    loginPage=u5168u5c40u6d88u606fuff1au767bu5f55u9875u9762
    user=u5168u5c40u6d88u606fuff1au7528u6237u540d
    pass=u5168u5c40u6d88u606fuff1au5bc6  u7801
    login=u5168u5c40u6d88u606fuff1au767bu5f55
    resultPage=u767bu5f55u7ed3u679c
    # u5728Actionu4e2du4f7fu7528u7684u56fdu9645u5316u6d88u606f
    failTip=u5168u5c40u6d88u606fuff1au5bf9u4e0du8d77uff0cu60a8u4e0du80fdu767bu5f55uff01
    succTip=u5168u5c40u6d88u606fuff1au6b22u8fceuff0cu60a8u5df2u7ecfu767bu5f55uff01
    # u5728Actionu6821u9a8cu89c4u5219u6587u4ef6u4e2du4f7fu7528u7684u56fdu9645u5316u6d88u606f
    username.required=u5168u5c40u6d88u606fuff1au7528u6237u540du662fu5fc5u9700u7684uff01
    <?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>
        <constant name="struts.i18n.encoding" value="GBK"/>
        <!-- 指定加载baseName为mess的国际化消息资源文件 -->
        <constant name="struts.custom.i18n.resources" value="mess"/>
        <!-- 配置了一个包元素 -->
           <package name="lee" extends="struts-default">
            <action name="login" class="org.crazyit.app.action.LoginAction">
                <result name="input">/WEB-INF/content/loginForm.jsp</result>
                <result>/WEB-INF/content/result.jsp</result>
                <result name="error">/WEB-INF/content/result.jsp</result>
            </action>
            <action name="*">
                <result>/WEB-INF/content/{1}.jsp</result>
            </action>
        </package>
    </struts>
    package org.crazyit.app.action;
    
    import com.opensymphony.xwork2.*;
    
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    public class LoginAction extends ActionSupport
    {
        // 下面定义了两个成员变量,用于封装请求参数
        private String username;
        private String password;
    
        // username的setter和getter方法
        public void setUsername(String username)
        {
            this.username = username;
        }
        public String getUsername()
        {
            return this.username;
        }
    
        // password的setter和getter方法
        public void setPassword(String password)
        {
            this.password = password;
        }
        public String getPassword()
        {
            return this.password;
        }
    
        // 处理用户请求的execute方法
        public String execute() throws Exception
        {
            ActionContext ctx = ActionContext.getContext();
            if (getUsername().equals("crazyit.org")
                && getPassword().equals("leegang"))
            {
                ctx.getSession().put("user" , getUsername());
                // 获取国际化消息
                ctx.put("tip" , getText("succTip"));
                return SUCCESS;
            }
            // 获取国际化消息
            ctx.put("tip" , getText("failTip"));
            return ERROR;
        }
    }
    <?xml version="1.0" encoding="GBK"?>
    <!DOCTYPE validators PUBLIC
        "-//Apache Struts//XWork Validator 1.0.3//EN"
        "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
    <validators>
        <!-- 校验Action的name属性 -->
        <field name="username">
            <!-- 指定name属性必须满足必填规则 -->
            <field-validator type="requiredstring">
                <param name="trim">true</param>
                <message key="username.required"/>
            </field-validator>
        </field>
    </validators>
  • 相关阅读:
    POJ 1392 Ouroboros Snake 欧拉回路
    POJ 1275 Cashier Employment 差分约束+二分答案
    POJ 1780 Code 欧拉回路+手写栈DFS
    POJ 1300 Door Man 欧拉路的判断
    HDU1534 Schedule Problem 差分约束
    POJ 3169 Layout 差分约束
    POJ 1364 King 差分约束 找负环
    ZOJ 2770 Burn the Linked Camp 差分约束+SPFA
    Zoj 2027 Travelling Fee 最短路变形
    Poj 2263 Heavy Cargo Floyd 求最大容量路
  • 原文地址:https://www.cnblogs.com/tszr/p/12364591.html
Copyright © 2011-2022 走看看