
本站地址:http://www.bajiao123.com

实战struts2:用户登录
</action>
</package>
</struts>
<action name="Logon!*" method="{1}"
class="com.cleversoft.struts2.demo.Logon">
<result type="redirect-action">Menu</result>
<result name="input">/Logon.jsp</result>
</action>
<html>
<head>
<title>Missing Feature</title>
</head>
<body>
<p>
This feature is under construction. Please try again in the next interation.
</p>
</body>
</html>
7. 运行
访问http://localhost:8080/struts2/Welcome.action
运行结果:

登录

输入校验

登录成功


8.
本地化输出
首先需要添加资源文件
package.properties:
requiredstring = $\{getText(fieldName)} is required.
password = Password
username = User Name
接着需要修改Logon-validation.xml和Logon.jsp
Logon-validation.xml:
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="username">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
</validators>
Logon.jsp:

<%
@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Login</title>
</head>
<body>
<s:form action="Logon">
<s:textfield label="%{getText('username')}" name="username"/>
<s:password label="%{getText('password')}" name="password" />
本站地址:http://www.bajiao123.com

