Search code examples
strutsstruts-1

Error in my simple struts application


Error: inconvertible types

my loginAction file's code:

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);
    }
}

my struts-config file's code:

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

my loginform file's code

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; } }


Solution

  • I think This will work ..

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