-1
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    HttpSession sesion = request.getSession();
    PrintWriter out = response.getWriter();

    String num = request.getParameter("num");
    String password = request.getParameter("password");
    sesion.setAttribute("num", num);

    Queries sql = new Queries();
    if (sql.login(num, password)) {
        response.sendRedirect("private.jsp");
    } else {
        request.setAttribute("error", "Error on login");
        RequestDispatcher dispatcher = 
        ServletContext().getRequestDispatcher("login.jsp"); // This line doesn't working
        dispatcher.forward(request, response);
    }

}

I have a error with servletContext(). According Netbeans Cannot find symbol. I want to redirect to login.jsp with a parameter.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
jjprz
  • 55
  • 1
  • 2
  • 8

2 Answers2

0

Assuming youre extending HttpServlet the servlet context is found using getServletContext

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("login.jsp");
Reimeus
  • 158,255
  • 15
  • 216
  • 276
0

Instead of taking ServletContext ,you can use request scope to forward it to login.jsp below is the one liner code.

request.getRequestDispatcher("login.jsp").forward(request,response);
Sagar Kadu
  • 251
  • 2
  • 18