2012-10-25 29 views
1

錯誤:不可兌換類型錯誤在我簡單的Struts應用程序

我在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> 

我的登錄表單文件的代碼

public class LoginForm { String userName; String password; 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() { return password; } public void setPassword(String password) { this.password = password; } }

+1

什麼是代碼中的成功和失敗(首都)? –

+1

你使用Struts或Struts2嗎?你的代碼來自Struts,但在你的問題中,你正在尋求Struts2 ... – Pigueiras

+1

爲什麼人們在這麼做?如果他不解釋他正在使用的框架是什麼,那麼這可能是一個好問題? – Pigueiras

回答

1

我認爲這將起作用..

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