/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.satesoft.test;import org.apache.struts.validator.ValidatorActionForm;public class UserForm extends ValidatorActionForm {
/**
*
*/
private static final long serialVersionUID = 1L;
private String name; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}
*****************************************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<data-sources />
<form-beans>
<form-bean name="userform" type="com.satesoft.test.UserForm"></form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action input="/index.jsp" path="/show" name="userform" type="com.satesoft.test.ShowAction" validate="true">
<forward name="foward" path="/show.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="ApplicationResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
*****************************************************************
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
<title>
index
</title>
</head>
<body bgcolor="#ffffff">
<html:form action="show.do" method="post">
<html:text property="name"/>
<html:submit title="确定"/>
<html:cancel title="取消">
<html:errors property="error.verify.user"/>
<html:errors property="name"/>
</html:cancel>
</html:form>
<html:errors/></body>
</html>
*************************************************************
errors.required={0} is required.
errors.minlength={0} cannot be less than {1} characters.
errors.maxlength={0} cannot be greater than {1} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid email address
user.name.required=user name
******************************************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
<form-validation>
<formset>
<form name="userForm">
<field property="name" depends="required">
<arg0 key="user.name"/>
</field>
</form>
</formset>
</form-validation>
****************************************************
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.satesoft.test;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;public class ShowAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm uf = (UserForm)form;
System.out.println(uf.getName());
return mapping.findForward("foward");
}
}
页面出来了,可是验证一点反应也没有
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.satesoft.test;import org.apache.struts.validator.ValidatorActionForm;public class UserForm extends ValidatorActionForm {
/**
*
*/
private static final long serialVersionUID = 1L;
private String name; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}
*****************************************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<data-sources />
<form-beans>
<form-bean name="userform" type="com.satesoft.test.UserForm"></form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action input="/index.jsp" path="/show" name="userform" type="com.satesoft.test.ShowAction" validate="true">
<forward name="foward" path="/show.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="ApplicationResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
*****************************************************************
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
<title>
index
</title>
</head>
<body bgcolor="#ffffff">
<html:form action="show.do" method="post">
<html:text property="name"/>
<html:submit title="确定"/>
<html:cancel title="取消">
<html:errors property="error.verify.user"/>
<html:errors property="name"/>
</html:cancel>
</html:form>
<html:errors/></body>
</html>
*************************************************************
errors.required={0} is required.
errors.minlength={0} cannot be less than {1} characters.
errors.maxlength={0} cannot be greater than {1} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid email address
user.name.required=user name
******************************************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
<form-validation>
<formset>
<form name="userForm">
<field property="name" depends="required">
<arg0 key="user.name"/>
</field>
</form>
</formset>
</form-validation>
****************************************************
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.satesoft.test;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;public class ShowAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm uf = (UserForm)form;
System.out.println(uf.getName());
return mapping.findForward("foward");
}
}
页面出来了,可是验证一点反应也没有
<html:form action="show.do" method="post">
<html:text property="name"/>
<html:submit title="确定"/>
<html:cancel title="取消">
<html:errors property="error.verify.user"/>
<html:errors property="name"/>
</html:cancel>
</html:form>
其他的没看,但这个<html:form action="show.do" method="post"> 应该为<html:form action="show.do" method="post" onsubmit="return validateUserForm (this);">
....
</html:form>
<html:javascript formName="adminForm"/>(补上!)你先试着把这2点补上,看看
<html:form action="show.do" method="post">
<html:text property="name"/>
<html:submit title="确定"/>
<html:cancel title="取消">
<html:errors property="error.verify.user"/>
<html:errors property="name"/>
</html:cancel>
</html:form>
其他的没看,但这个<html:form action="show.do" method="post"> 应该为<html:form action="show.do" method="post" onsubmit="return validateUserForm (this);">
....
</html:form>
<html:javascript formName="adminForm"/>(补上!)你先试着把这2点补上,看看
onsubmit="return validateUserForm (this);">
<html:javascript formName="[color=#FF0000]userForm[/color]"/>
user.name.required=user name
<arg0 key="user.name.required"/> /99/99