📄 loginservlet.java
字号:
package com.abc.dl.servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet {
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username != null && password !=null && username.equals(password)) {
HttpSession session = request.getSession();
session.setAttribute("login", "true");
request.getRequestDispatcher("/servlet/main.html").forward(request, response);
return;
}
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gbk");
//response.setHeader("Content-type","text/html") //设置header
//response. _________("Pragma", "no-cache"); //设置header信息
//response. __________ ("Cache-control", "no-cache");
//response.setDateHeader("Expires",0); //设置时间header
//response._________; //该servlet组件输出image/jpeg类型文档
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
session.setAttribute("login", "false");
request.getRequestDispatcher("/login.html").include(request, response);
out.println("Please check and refill the form.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -