我的简单struts应用程序出错

时间:2012-10-25 07:57:11

标签: struts struts-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文件的代码

  

公共类LoginForm   {String userName;字符串密码;      public String getUserName(){      System.out.println(“Inside getter”+ userName);      return userName;      }      public void setUserName(String userName){       System.out.println(“Inside setter”+ userName);       this.userName = userName;      }      public String getPassword(){       返回密码;     }   public void setPassword(String password){    this.password =密码;   }   }

1 个答案:

答案 0 :(得分:1)

我认为这会有效..

if (loginForm.getUserName().equals(loginForm.getPassword())) 
{
    return mapping.findForward("success");
} 
else 
{
    return mapping.findForward("failure");
}