案例:判断登录用户是否为第一次登录,是则提示“欢迎,这是您第一次登录”;不是则提示“欢迎回来,您的上一次登录时间为(yyyy年MM月dd日 HH:mm:ss)”。
LoginServlet
@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.防止post请求中文乱码
request.setCharacterEncoding("utf-8");
//2.防止响应中文乱码
response.setContentType("text/html;charset=utf-8");
//3.得到前端传回来的数据
String username = request.getParameter("username");
String password = request.getParameter("password");
//4.逻辑判断 判断用户名是否为张三,密码是否为1