Java Struts ajax验证程序不工作
我的struts 2 ajax验证器不工作。所有的文件和JAR都在正确的位置。如果我在文本框中输入正确的值,验证仍然会启动,我尝试修复代码中的小更改,但问题仍然存在 index.jspJava Struts ajax验证程序不工作,java,ajax,jsp,struts2,Java,Ajax,Jsp,Struts2,我的struts 2 ajax验证器不工作。所有的文件和JAR都在正确的位置。如果我在文本框中输入正确的值,验证仍然会启动,我尝试修复代码中的小更改,但问题仍然存在 index.jsp <%@ taglib uri="/struts-tags" prefix="s"%> <%@ taglib uri="/struts-dojo-tags" prefix="d"%> <html> <head> <d:head/> &
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="/struts-dojo-tags" prefix="d"%>
<html>
<head>
<d:head/>
</head>
<body>
<marquee>Registration Form.............</marquee>
<s:form action="register">
<s:textfield name="name" label="Username"></s:textfield>
<s:textfield name="email" label="Email ID"></s:textfield>
<s:password name="password" label="Password"></s:password>
<d:submit validate="true" type="image" src="register-now.jpg">
</d:submit>
</s:form>
</body>
</html>
RegisterAction-Validator.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="name">
<field-validator type="requiredstring">
<message>Name can't be blank</message>
</field-validator>
</field>
<field name="email">
<field-validator type="requiredstring">
<message>Email ID can't be blank</message>
</field-validator>
<field-validator type="email">
<message>Please enter a valid email ID</message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message>Password can't be blank</message>
</field-validator>
<field-validator type="stringlength">
<param name="minLength">5</param>
<param name="maxLength">10</param>
<message>Password can't be less than 5 or greater than 10</message>
</field-validator>
</field>
</validators>
名称不能为空
电子邮件ID不能为空
请输入有效的电子邮件ID
密码不能为空
5.
10
密码不能小于5或大于10
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Struts2Starter</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Struts2Starter
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
支柱2
org.apache.struts2.dispatcher.ng.filter.strutspreadexecutefilter
支柱2
/*
确保在进行验证时,堆栈上确实存在值。如果没有,那么您的拦截器可能会在params拦截器使表单值可访问之前被调用
仔细检查它是否试图从您的操作中获取值。如果是,则RegisterAction中的所有表单值都需要getter/setter。名称/密码不仅仅是电子邮件。S2 dojo插件已被弃用。Struts的哪个版本?如果不提供,您如何知道一切都正确?
<?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="name">
<field-validator type="requiredstring">
<message>Name can't be blank</message>
</field-validator>
</field>
<field name="email">
<field-validator type="requiredstring">
<message>Email ID can't be blank</message>
</field-validator>
<field-validator type="email">
<message>Please enter a valid email ID</message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message>Password can't be blank</message>
</field-validator>
<field-validator type="stringlength">
<param name="minLength">5</param>
<param name="maxLength">10</param>
<message>Password can't be less than 5 or greater than 10</message>
</field-validator>
</field>
</validators>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Struts2Starter</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>