mardi 7 février 2017

Remanent Null Pointer Exception [duplicate]

This question already has an answer here:

sorry if my question is duplicated i already searched for something similar but didnt find results. I have a residual null pointer exception.

Caused by the following scenario.

I started a local Java Web Application , by the time i tried to log in, the app. i have not started my Database Server. That caused a null pointer exception when triying to retrieve the user information.

So i started the database server and tried to log. , but the null pointer exception remained. Clearing cache didnt work, the unique solution was restarting my service at the server. and it worked normally.

I cant stop and re-star services at my productive server so i would like to know if anybody has an idea to solve this problem lets call it (Cache Null Pointer Exception or somehing)

Thanks in advance i provide part of my log-in code.

WebServlet("/login")
public class Login extends HttpServlet
{

//metodo encargado de la gestión del método POST
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
    ResultSet rs = null;
    HttpSession sesion = request.getSession();
    String usu, pass;
    usu = request.getParameter("user");
    pass = request.getParameter("password");
    String usernamedb = null,id_usuariodb = null,passworddb = null;

    //Buscamos el usuario en la base de datos
    //1.- El query
    String sql = "select ID_USUARIO, NOMBRE, CONTRASENA from USUARIO where NOMBRE = '" + usu + "'";
    rs = DaoMVC.readUser(sql);

    try
    {
        ;


        while (rs.next())
        { // Posicionar el cursor

            //---------Se  leen los resultados individuales desde un result set------

            id_usuariodb = rs.getString(1);
            usernamedb = rs.getString(2); // Adquirimos el valor que viene db2
            passworddb = rs.getString(3); // Adquirimos el valor que viene db2

//              System.out.println("Se generó el query " + id_usuariodb + " " + usernamedb + " " + passworddb);
        }//fin while


    }
    catch (SQLException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }//fin del catch


    if (usu.equals(usernamedb) && pass.equals(passworddb) && sesion.getAttribute("usuario") == null)
    {
        //Si coincide el usuario y contraseña y además no hay sesión iniciada
        sesion.setAttribute("usuario", usu);
        ArrayList<ModelRazonesSociales> uniList = new ArrayList<ModelRazonesSociales>();
        uniList = DaoMVC.listaRazonSocial();
       request.setAttribute("list", uniList);
        //Redirijo a página con infor de login exitoso
        //response.sendRedirect("Secure/home.jsp");

        request.getRequestDispatcher("/Secure/home.jsp").forward(request,
            response);

    }//Fin del if de login correcto

    else
    {//caso contrario regreso a index
        response.sendRedirect("index.jsp");
    }//fin del else login incorrecto


}




Aucun commentaire:

Enregistrer un commentaire