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

    <?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="*">
                <result>/WEB-INF/content/{1}.jsp</result>
            </action>
        </package>
    </struts>
    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
    #在JSP页面使用的JSP范围的资源文件
    loginPage=JSP消息:登录页面
    user=JSP消息:用户名
    pass=JSP消息:密  码
    login=JSP消息:登录
    <%--
    网站: <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>
    <!-- 加载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>
    <?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="*">
                <result>/WEB-INF/content/{1}.jsp</result>
            </action>
        </package>
    </struts>
    #在JSP页面使用的JSP范围的资源文件
    loginPage=JSP消息:登录页面
    user=JSP消息:用户名
    pass=JSP消息:密  码
    login=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
    <?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 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消息:登录
    <%--
    网站: <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;
            }
            else
            {
                // 获取国际化消息
                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>
    failTip=Package消息:对不起,您不能登录!
    succTip=Package消息:欢迎,您已经登录!
    username.required=Package消息:用户名是必需的!
    failTip=Package Scope:Sorry,You can't log in!
    succTip=Package Scope:welcome,you has logged in!
    username.required=Package Scope: User Name is required!
    failTip=Packageu6d88u606fuff1au5bf9u4e0du8d77uff0cu60a8u4e0du80fdu767bu5f55uff01
    succTip=Packageu6d88u606fuff1au6b22u8fceuff0cu60a8u5df2u7ecfu767bu5f55uff01
    username.required=Packageu6d88u606fuff1au7528u6237u540du662fu5fc5u9700u7684uff01
    #在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消息:登录
  • 相关阅读:
    mkdir()和mkdirs() 的区别
    JAVA 多线程学习
    遇到问题(1)
    7.12计划
    Android 中Int类型和String类型的转换
    Android Binder机制学习笔记
    7.11计划,做个没心没肺的人
    RTL行为级仿真、综合后门级功能仿真和时序仿真
    定向锚文本(高级) 站内站策略(高级) 链轮模式(高级) 站群模式(高级)
    优化长尾关键词基础指南
  • 原文地址:https://www.cnblogs.com/tszr/p/12364622.html
Copyright © 2011-2022 走看看