1

错误:不可转换的类型

我的 loginAction 文件的代码:

public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception 
{
    LoginForm loginForm = (LoginForm) form;

    if (loginForm.getUserName().equals(loginForm.getPassword())) 
    {
        return mapping.findForward(SUCCESS);
    } 
    else 
    {
        return mapping.findForward(FAILURE);
    }
}

我的 struts-config 文件的代码:

<action-mappings>
    <action input="/login.jsp" name="LoginForm" path="/Login" scope="session"                type="com.strutsmyaction.LoginAction">
         <forward name="success" path="/success.jsp" />
         <forward name="failure" path="/failure.jsp" />
    </action>
</action-mappings>

我的登录表单文件的代码

公共类 LoginForm { 字符串用户名;字符串密码;public String getUserName() { System.out.println("内部getter "+userName); 返回用户名;} public void setUserName(String userName) { System.out.println("Inside setter "+userName); this.userName = 用户名;} public String getPassword() { 返回密码;} public void setPassword(String password) { this.password = password; } }

4

1 回答 1

1

我认为这会奏效..

if (loginForm.getUserName().equals(loginForm.getPassword())) 
{
    return mapping.findForward("success");
} 
else 
{
    return mapping.findForward("failure");
}
于 2014-01-16T13:04:50.563 回答