我尝试添加所有可能的解决方案和补丁,但事情不起作用。程序每次都绕过验证
我正在尝试实施电子邮件验证
我的项目结构
我尝试了不同的dtd架构,但它们完全相同。我怎样才能弄清楚验证的错误
我的index.jsp
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<STYLE type="text/css">
.errorMessage{color:red;}
</STYLE>
</head>
<body>
<s:form action="register" method="post" validate="true">
<s:textfield name="email" label="Enter Email Id"></s:textfield>
<s:submit value="register"></s:submit>
</s:form>
</body>
</html>
struts.xml中
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="register" class="com.RegisterAction">
<result name="input">index.jsp</result>
<result>welcome.jsp</result>
</action>
</package>
</struts>
RegisterAction.java
package com;
import com.opensymphony.xwork2.ActionSupport;
public class RegisterAction extends ActionSupport{
private String email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String execute(){
return "success";
}
}
寄存器的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="email">
<field-validator type="requiredstring">
<message>Email Id can't be blank</message>
</field-validator>
<field-validator type="email">
<message>Please enter correct email id</message>
</field-validator>
</field>
</validators>
的welcome.jsp
<%@ taglib uri="/struts-tags" prefix="s" %>
Email Id is:,<s:property value="email"/>
答案 0 :(得分:0)
将验证文件名更改为RegisterAction-validation.xml