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);
}
}
servletContext()
出错。根据Netbeans 找不到符号。我想使用参数重定向到 login.jsp 。
答案 0 :(得分:0)
假设您正在使用HttpServlet
getServletContext
servlet上下文
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("login.jsp");
答案 1 :(得分:0)
您可以使用请求范围来代替ServletContext 将它转发到login.jsp下面是一个班轮代码。
request.getRequestDispatcher("login.jsp").forward(request,response);