体会真正的Struts开发3(4)

下面我们重新设计我们的LogonForm<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

改为

public class LogonForm extends ValidatorForm/*ActionForm*/

我们注释掉ActionForm的Validate()函数。

我们配置Struts-config.xml文件,在文件最后增加

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">

<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />

</plug-in>

下面我们修改validation.xml文件

增加

<form name="logonForm">

<field

property="userName"

depends="required">

<arg0 key="userName" resource="false"/>

</field>

<field

property="password"

depends="required">

<arg0 key="password" resource="false"/>

</field>

</form>

同时在资源文件中增加

errors.required={0} is required.

重新启动程序,那么登陆程序服务器端验证就起作用了。

下面我们来添加Client端的Javascript验证。

修改Logon.jsp

<%@ page language="java" contentType="text/html;charset=UTF-8"%>

<%@ taglib uri="/tags/struts-bean" prefix="bean"%>

<%@ taglib uri="/tags/struts-html" prefix="html"%>

<%@ page errorPage="error.jsp" %>

<html>

<head>

<title><bean:message key="Logon"/></title>

</head>

<body>

<html:errors property="hbm.session.error"/>

<html:errors property="no.user"/>

<html:errors property="hbm.session.query"/>

<html:form action="/jsp/logon.do" focus="userName"

οnsubmit="return validateLogonForm(this)">

<bean:message key="Logon.UserName"/> : <html:text property="userName"/><html:errors property="userName"/></br>

<bean:message key="Logon.Password"/> : <html:text property="password"/><html:errors property="password"/></br>

<html:submit>

<bean:message key="Logon.Submit"/>

</html:submit>

</html:form>

<html:javascript dynamicJavascript="true" staticJavascript="true" formName=logonForm/>

<body>

</html>

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 339pt; HEIGHT: 139.5pt" type="#_x0000_t75"><img src="http://dev.csdn.net/Develop/ArticleImages/26/26120/CSDN_Dev_Image_2004-3-271457470.png" o=""></shape>

OK

下一此按Excel计划开始贯彻前期思想。

谢谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值