2 yrgyrg0409 yrgyrg0409 于 2014.03.13 13:35 提问

servlet中的空指针异常问题

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=utf-8");
String registername = "";
String registeremail = "";
String registerpassword = "";
List params = new ArrayList();
boolean flag = false;

    DataOutputStream output=new DataOutputStream(response.getOutputStream());   
    registername = request.getParameter("registername");
    registeremail = request.getParameter("registeremail");
    registerpassword = request.getParameter("registerpassword");

// System.out.println(registername);
// System.out.println(registeremail);
// System.out.println(registerpassword);
params.add(registername);
params.add(registeremail);
params.add(registerpassword);

    try {   
        flag = service.register(params);
        if(flag){
            output.writeUTF("SUCCESS");
        }else{
            output.writeUTF("FAIL");
        }
    }catch(Exception e){
        e.printStackTrace();
    }finally{
        output.flush();
        output.close();
    }       
}

这段代码一直在flag = service.register(params); 这行报告空指针异常,求解??
service的定义private RegisterService service= new RegisterDao();
RegisterService是接口,register方法的定义

public boolean register(List params) {
// TODO Auto-generated method stub
boolean flag = false;
String sql ="insert into userinfo(username,email,password) values(?,?,?)";
try {
jdbcUtil.getConnection();
flag = jdbcUtil.updateByPreparedStatement(sql, params);

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }finally{
        jdbcUtil.releaseConn();
    }
    return flag;
}

1个回答

woaihouzhuang
woaihouzhuang   2014.03.13 16:56

debug 调试一下

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!