1)struts.xml
<action name="Logon" class="com.meetcomet.action.logon"> <result name="input">/login.jsp</result> <result name="success">/welcome.jsp</result> <result name="error">/error.jsp</result> </action>
2)login.jsp
<%@page language="java"import="java.util.*"pageEncoding="GBK"%> <%@taglib prefix="s"uri="/struts-tags"%> <html> <body> <s:text name="greetings"></s:text><br> <s:form action="Logon" method="post" > <s:textfield key="username"/> <s:textfield key="password"/> <s:textfield key="email"/> <s:submit value="确定"/> </s:form><s:text name="contact"></s:text> </body> </html>
4)Logon中没有验证代码
5)在和Logon同一位置文件名为logon.java,建立的验证文件logon-validation.xml
<?xml version="1.0" encoding="UTF-8"?> <!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>账号不能为空</message> </field-validator> </field> <field name="password"> <field-validator type="requiredstring"> <message>密码不能为空</message> </field-validator> <field-validator type="stringlength"> <param name="minLength">6</param> <param name="maxLength">10</param> <message>密码在 ${minLength} -${maxLength}位之间</message> </field-validator> </field> <field name="email"> <field-validator type="requiredstring"> <message>email不能为空</message> </field-validator> <field-validator type="email"> <message>非email格式</message> </field-validator> </field> </validators>
6)国际化可为
<field name="email"> <field-validator type="requiredstring"> <message>${getText("login.email.isnull")</message> </field-validator> <field-validator type="email"> <message>${getText("login.email.noEmail")</message> </field-validator> </field>
---------------------------------------------------------------------
后来发现,login的action名字还是用login比较好,而不要用自己编的logon,因为Action.LOGIN这个值为"login".