struts2的编辑校验为什么没有效果
ACTION文件:
package action;
import com.opensymphony.xwork2.ActionSupport;
public class OneAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String user;
private String pass;
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
}
OneAction-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="user">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>*必须输入名字</message>
</field-validator>
</field>
<field name="pass">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>パスワード必要</message>
</field-validator>
</field>
</validators>
jsp文件:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登録画面</title>
</head>
<body>
<s:form action="login">
<s:fielderror></s:fielderror>
<s:textfield name="user" label="ユーザー名"></s:textfield>
<s:password name="pass" label="パスワード欄"></s:password>
<s:submit value="提出" label=""></s:submit>
</s:form>
</body>
</html>
structs.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="oneaction" extends="struts-default" namespace="/">
<action name="login" class="action.OneAction">
<result name="success">success.jsp</result>
<result name="input">login.jsp</result>
</action>
</package>
</struts>
------解决方案--------------------
完全正确 OneAction-validation.xml要放在action同一个包中。