Struts2验证甚至不起作用

Struts2验证甚至不起作用,struts2,Struts2,我还配置了Struts2基本验证的所有设置,但没有任何东西对我有效 我的login.jsp文件 <%@taglib uri="/struts-tags" prefix="s" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title&g

我还配置了Struts2基本验证的所有设置,但没有任何东西对我有效

我的login.jsp文件

<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
    <title>Login Page</title>
    <s:head />
  </head>
  <body>
    <s:actionerror/>
    <s:form action="Login" method="post">
      <s:textfield name="userName" label="User Name" />
      <s:password name="password" label="Password" />
      <s:submit value="Login" />
      <s:fielderror></s:fielderror>
    </s:form>
  </body>
</html>
我的struts2.xml文件是,


login.jsp
login.jsp
我将LoginAction-validation.xml文件放在Action类所在的包中


请查看我的代码并帮助我解决验证问题。

您将在action类的execute方法中返回相同的login.jsp页面。 因此,每次按enter键时,都会显示带有空字段的登录页面

根据action类返回的字符串,尝试创建一个重定向到的附加jsp


除此之外,我看不出有任何问题。

您使用的是Struts2的默认模板吗?你能把你的
LoginAction validation.xml
放进去吗?你用什么进行测试?什么对你不起作用?请发布您的XML文件
package com.test;
import com.opensymphony.xwork2.ActionSupport;


public class LoginAction extends ActionSupport {

private static final long serialVersionUID = 1L;
    private String userName;
    private String password;

    public LoginAction() {
    }

    public String execute() {
        return "SUCCESS";
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }


}
<package name="default" namespace="/" extends="struts-default">
    <action name="Login" class="com.test.LoginAction" method="execute">
        <result name="SUCCESS">login.jsp</result>
        <result name="input">login.jsp</result>
    </action>
</package>
</struts>