0

Getting null pointer exception at line --

if(lForm.getUserId()!=null && lForm.getPassword()!= null){

Please help

package com.app.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;



import com.app.form.LoginForm;

public class LoginAction extends Action {



@Override

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

LoginForm lForm = (LoginForm) form;
String forwardString = "";

//lForm.setUserId("shats");
try{
    if(lForm.getUserId()!=null && lForm.getPassword()!= null){
if(lForm.getUserId().equals("shats") && lForm.getPassword().equals("admin"))
{
    forwardString = "success";
}
else
{
    forwardString = "failure";
}
    }
}
catch(Exception e){
    System.out.println("Error ::::::"+e);
}
forwardString = "success";
return mapping.findForward(forwardString);

}

}
shatakshi
  • 165
  • 8

1 Answers1

0

Probably when you call the method execute the object "form" is not initiated, you should check the code where you call the method "execute".

In the previous code you should have something like:

LoginForm form = new LoginForm(.....);
//probably something in the middle
ActionForward af = execute(mapping, form, request, response);

I think you don't have the line LoginForm form = new LoginForm(.....);

leonardo vet
  • 119
  • 14