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";
}