获取空指针异常:: struts 1.3

时间:2016-08-06 17:34:18

标签: java

在行 -

获取空指针异常
if(lForm.getUserId()!=null && lForm.getPassword()!= null){

请帮忙

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

}

}

1 个答案:

答案 0 :(得分:0)

当你调用方法时,可能会执行对象" form"如果没有启动,您应该检查调用方法的代码"执行"。

在上一段代码中,你应该有类似的东西:

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

我认为你没有使用LoginForm形式的行= new LoginForm(.....);