<?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 "> <- defined core Struts controller 2:! StrutsPrepareAndExecuteFilter -> <filter> ! <- define the core name Filter -> <filter-name> Struts2 </ filter-name> <! - define the core Filter implementation class -> <filter- class > org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <-! StrutsPrepareAndExecuteFilter to handle all HTTP requests -> <Mapping-filter> <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>
# Range in JSP JSP pages using resource files the LoginPage = JSP the Message: the Login Page the User = JSP the Message: the User the Name Pass = JSP the Message: the User Pass the Login = JSP the Message: the 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 = log results
welcomemsg = {0}, Hello! The time now is {1}!
resultPage=Log In Result
welcomeMsg={0},Hello!Now is {1}!
resultPage=\u767b\u5f55\u7ed3\u679c
welcomeMsg={0}\uff0c\u60a8\u597d\uff01\u73b0\u5728\u65f6\u95f4\u662f{1}\uff01
# Range in JSP JSP pages using resource files the LoginPage = JSP message: login page the User = JSP news: Username Pass = JSP message: Password the Login = JSP message: Login
<%-- 网站: <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 = "the Type-the Content" Content = "text / HTML; GBK charset =" /> <- - tag used to output a text message international!> <title> <S: text name = "LoginPage "/> </ title> </ head> <body> <S: Action form =" "> Login ! <- form tag attributes used to output key international message -> <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> <jsp:useBean id="d" class="java.util.Date" scope="page"/> ${requestScope.tip}<br/> <!-- 输入带占位符的国际化消息 --> <s:text name="welcomeMsg"> <s:param><s:property value="username"/></s:param> <s:param>${d}</s:param> </s:text> </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>
#\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 = log results
welcomemsg = {0}, Hello! The time now is {1}!
resultPage=Log In Result
welcomeMsg={0},Hello!Now is {1}!
resultPage=\u767b\u5f55\u7ed3\u679c
welcomeMsg={0}\uff0c\u60a8\u597d\uff01\u73b0\u5728\u65f6\u95f4\u662f{1}\uff01
# Range in JSP JSP pages using resource files the LoginPage = JSP message: login page the User = JSP news: Username Pass = JSP message: Password the Login = JSP message: Login
# Range in JSP JSP pages using resource files the LoginPage = JSP the Message: the Login Page the User = JSP the Message: the User the Name Pass = JSP the Message: the User Pass the Login = JSP the Message: the Login
failTip = Action Message: {0 }, I'm sorry, you can not log in! succTip = Action Message: {0 }, welcome, you are already logged in! username.required = Action Message: The user name is required!
failTip=Action Scope:Sorry,{0},You can't log in!
succTip=Action Scope:welcome,{0},you has logged in!
username.required=Action Scope: User Name is required!
failTip=Action\u6d88\u606f\uff1a{0}\uff0c\u5bf9\u4e0d\u8d77\uff0c\u60a8\u4e0d\u80fd\u767b\u5f55\uff01 succTip=Action\u6d88\u606f\uff1a{0}\uff0c\u6b22\u8fce\uff0c\u60a8\u5df2\u7ecf\u767b\u5f55\uff01 username.required=Action\u6d88\u606f\uff1a\u7528\u6237\u540d\u662f\u5fc5\u9700\u7684\uff01
<?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>
Package Penalty for org.crazyit.app.action; Import com.opensymphony.xwork2 *. ; / ** * the Description: * the website: <a href=" http://www.crazyit.org "> crazy Java Union </a> * a Copyright (C), 2001-2016, Yeeku.H.Lee * This Program IS protected by a Copyright Laws. * a Program the Name: * a a Date : * @author Yeeku.H.Lee [email protected] * @version 1.0 * / public class the LoginAction the extends ActionSupport { // following the two member variables defined for encapsulation request parameter Private String username; privatePassword String; // username setter and getter methods public void setUsername (String username) { the this .username = username; } public String the getUsername () { return the this .username; } // password setter and getter methods public void the setPassword ( password String) { the this .password = password; } public String the getPassword () { return the this .password; } // processing method execute user request 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" , new String[]{username})); return SUCCESS; } // 获取国际化消息 ctx.put("tip" , getText("failTip" , new String[]{username})); return ERROR; } }