<?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
#\u5728JSP\u9875\u9762\u4f7f\u7528\u7684JSP\u8303\u56f4\u7684\u8d44\u6e90\u6587\u4ef6 loginPage=JSP\u6d88\u606f\uff1a\u767b\u5f55\u9875\u9762 errorPage=JSP\u6d88\u606f\uff1a\u9519\u8bef\u9875\u9762 succPage=JSP\u6d88\u606f\uff1a\u6210\u529f\u9875\u9762 failTip=JSP\u6d88\u606f\uff1a\u5168\u5c40\u6d88\u606f\uff1a\u5bf9\u4e0d\u8d77\uff0c\u60a8\u4e0d\u80fd\u767b\u5f55\uff01 succTip=JSP\u6d88\u606f\uff1a\u5168\u5c40\u6d88\u606f\uff1a\u6b22\u8fce\uff0c\u60a8\u5df2\u7ecf\u767b\u5f55\uff01 user=JSP\u6d88\u606f\uff1a\u7528\u6237\u540d pass=JSP\u6d88\u606f\uff1a\u5bc6 \u7801 login=JSP\u6d88\u606f\uff1a\u767b\u5f55
#在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
#\u5728JSP\u9875\u9762\u4f7f\u7528\u7684JSP\u8303\u56f4\u7684\u8d44\u6e90\u6587\u4ef6 loginPage=JSP\u6d88\u606f\uff1a\u767b\u5f55\u9875\u9762 errorPage=JSP\u6d88\u606f\uff1a\u9519\u8bef\u9875\u9762 succPage=JSP\u6d88\u606f\uff1a\u6210\u529f\u9875\u9762 failTip=JSP\u6d88\u606f\uff1a\u5168\u5c40\u6d88\u606f\uff1a\u5bf9\u4e0d\u8d77\uff0c\u60a8\u4e0d\u80fd\u767b\u5f55\uff01 succTip=JSP\u6d88\u606f\uff1a\u5168\u5c40\u6d88\u606f\uff1a\u6b22\u8fce\uff0c\u60a8\u5df2\u7ecf\u767b\u5f55\uff01 user=JSP\u6d88\u606f\uff1a\u7528\u6237\u540d pass=JSP\u6d88\u606f\uff1a\u5bc6 \u7801 login=JSP\u6d88\u606f\uff1a\u767b\u5f55
<?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
#\u5728JSP\u9875\u9762\u4f7f\u7528\u7684JSP\u8303\u56f4\u7684\u8d44\u6e90\u6587\u4ef6 loginPage=JSP\u6d88\u606f\uff1a\u767b\u5f55\u9875\u9762 errorPage=JSP\u6d88\u606f\uff1a\u9519\u8bef\u9875\u9762 succPage=JSP\u6d88\u606f\uff1a\u6210\u529f\u9875\u9762 failTip=JSP\u6d88\u606f\uff1a\u5168\u5c40\u6d88\u606f\uff1a\u5bf9\u4e0d\u8d77\uff0c\u60a8\u4e0d\u80fd\u767b\u5f55\uff01 succTip=JSP\u6d88\u606f\uff1a\u5168\u5c40\u6d88\u606f\uff1a\u6b22\u8fce\uff0c\u60a8\u5df2\u7ecf\u767b\u5f55\uff01 user=JSP\u6d88\u606f\uff1a\u7528\u6237\u540d pass=JSP\u6d88\u606f\uff1a\u5bc6 \u7801 login=JSP\u6d88\u606f\uff1a\u767b\u5f55
resultPage=登录结果
resultPage=Log In Result
resultPage=\u767b\u5f55\u7ed3\u679c
#在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=Package\u6d88\u606f\uff1a\u5bf9\u4e0d\u8d77\uff0c\u60a8\u4e0d\u80fd\u767b\u5f55\uff01 succTip=Package\u6d88\u606f\uff1a\u6b22\u8fce\uff0c\u60a8\u5df2\u7ecf\u767b\u5f55\uff01 username.required=Package\u6d88\u606f\uff1a\u7528\u6237\u540d\u662f\u5fc5\u9700\u7684\uff01
#在JSP页面使用的JSP范围的资源文件 loginPage=JSP Message:Login Page user=JSP Message:User Name pass=JSP Message:User Pass login=JSP Message:Login
#\u5728JSP\u9875\u9762\u4f7f\u7528\u7684JSP\u8303\u56f4\u7684\u8d44\u6e90\u6587\u4ef6 loginPage=JSP\u6d88\u606f\uff1a\u767b\u5f55\u9875\u9762 errorPage=JSP\u6d88\u606f\uff1a\u9519\u8bef\u9875\u9762 succPage=JSP\u6d88\u606f\uff1a\u6210\u529f\u9875\u9762 failTip=JSP\u6d88\u606f\uff1a\u5168\u5c40\u6d88\u606f\uff1a\u5bf9\u4e0d\u8d77\uff0c\u60a8\u4e0d\u80fd\u767b\u5f55\uff01 succTip=JSP\u6d88\u606f\uff1a\u5168\u5c40\u6d88\u606f\uff1a\u6b22\u8fce\uff0c\u60a8\u5df2\u7ecf\u767b\u5f55\uff01 user=JSP\u6d88\u606f\uff1a\u7528\u6237\u540d pass=JSP\u6d88\u606f\uff1a\u5bc6 \u7801 login=JSP\u6d88\u606f\uff1a\u767b\u5f55
resultPage=登录结果
resultPage=Log In Result
resultPage=\u767b\u5f55\u7ed3\u679c
#在JSP页面使用的JSP范围的资源文件 loginPage=JSP消息:登录页面 user=JSP消息:用户名 pass=JSP消息:密 码 login=JSP消息:登录