无法使用表达式语言为 Struts2 表单验证获取正确的代码



我希望使用表达式语言进行 struts2 表单验证。我已经尝试过,但EL没有显示任何消息。

这是我的登录代码.jsp

<s:form action="login" method="post">
    ${requestScope.invid}
    <s:textfield name="user" label="Username"/>
    ${requestScope.invpass}
    <s:password name="pass" label="Password" />
    <s:submit value="Log In" />
</s:form>

这是我的登录操作代码.java

public class LoginAction extends ActionSupport
{
private String user,pass;
HttpServletRequest request;
//setters and getters
public String execute()
{
    try
    {
        Session s=HibernateUtil.getSessionFactory().openSession();
        Hfslogin l2=(Hfslogin)s.get(Hfslogin.class,user);
        if(l2!=null)
        {
            if(l2.getPass().equals(pass))
            {
                return SUCCESS;
            }
            else
            {
                request.setAttribute("invpass","Password does not     match for this ID");
                return "relogin";
            }
        }
        else
        {
            request.setAttribute("invid","ID not registered");
            return "relogin";
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
        return "relogin";
    }
}
}

这是我的支柱.xml代码:

<action name="login" class="com.signin.LoginAction">
        <result name="relogin">login.jsp</result>
        <result name="success">Welcome.jsp</result>
</action>
当我

再次重新检查时,我得到了答案。我没有实现 ServletRequestAware 接口,因为我的"request"变量充当空值。ServletRequestAware实现了初始化请求的抽象方法。

最新更新