Java Web多组件协作实现用户登录验证(2)

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request,response);
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request,response);
    }
   
    public String getServletInfo(){
        return "short description";
    }

}

【4程序LoginFail.java】

package example.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LoginFail
 */
@WebServlet("/LoginFail")
public class LoginFail extends HttpServlet {
    private static final long serialVersionUID = 1L;

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html; charset=UTF-8");
        PrintWriter out=response.getWriter();
       
        out.print("<html>");
        out.print("<head>");
        out.print("<title>登录失败</title>");
        out.print("</head>");
        out.print("<body>");
        out.print("<h1>登录失败,请重新登录</h1>");
        RequestDispatcher dispatcher=request.getRequestDispatcher("login.html");
        dispatcher.include(request, response);
        out.print("</body>");
        out.print("<html>");
       
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request,response);
    }

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request,response);
    }
   
    public String getServletInfo(){
        return "short description";
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e92cdfa902d89b5ce5739f30923b1ccc.html