在Struts2中首次成功验证后,不会调用Execute方法

时间:2016-05-23 11:26:33

标签: java struts2

LoginAction.java

public void validate() {
        System.out.println("Validate method....!!!");
        System.out.println("Username....::"+this.username);
        System.out.println("password....::"+this.password);
        if (!username.equals("admin") || !password.equals("admin123")) {

            System.out.println("Action Error added....");
        this.addFieldError(username, "Username /Password are invalid. Try again.");

        }
    }

    public String execute() 
    {
        System.out.println("Execute method..");
        return "success";
    }

的Login.jsp

<s:form action="login.action">
 <s:fielderror cssStyle="color:red"/> 
  <s:textfield name="username" label="Username"/>
    <s:password name="password" label="Password"/>
    <s:submit value="Go"/>
</s:form>

首次运行应用程序时,将显示“登录”页面。如果我提供用户名和密码为&#34; admin&#34; &安培; &#34;为admin123&#34;它将导航到成功页面。如果我回到登录页面,如果提供错误的用户名或密码,它将验证并抛出错误。到这里它很好,但如果我给出正确的用户名和密码它应该导航到成功页面但是在验证方法之后,它没有执行execute method(),我没有得到什么问题。它是基于Struts2的应用程序。请帮帮我。

控制台日志:

WARNING: No configuration found for the specified action: 'login.action' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
Validate method....!!!
Username....::admin
password....::admin123
Execute method..
Validate method....!!!
Username....::admin
23 May, 2016 4:42:59 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: No configuration found for the specified action: 'login.action' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.
password....::dfsdfsdf
Action Error added....
23 May, 2016 4:42:59 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: No configuration found for the specified action: 'login.action' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.
Validate method....!!!
Username....::admin
password....::admin123
23 May, 2016 4:43:06 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn

0 个答案:

没有答案