一:用户名和密码容错显示
二:登录处理
三:登录成功,并提示密码。
百度云链接:链接: https://pan.baidu.com/s/13qRvqz7w1rh99gmHOk-0Bg
提取码: cpi4
四:各部分代码
html:
西南石油大学电子邮件系统 账号登录用户登录西南石油大学
servlet:
package com.swpu;import java.io.IOException;import java.io.PrintWriter;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 LoginServlet*/@WebServlet("/LoginServlet")public class LoginServlet extends HttpServlet {private static final long serialVersionUID = 1L;private String User;private String Password;/*** @see HttpServlet#HttpServlet()*/public LoginServlet() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.getWriter().append("Served at: ").append(request.getContextPath());}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.setContentType("text/html;charset=UTF-8");response.setCharacterEncoding("utf-8");PrintWriter out=response.getWriter();//获取参数User=request.getParameter("userName");Password=request.getParameter("passWord");if(User.equals("tom") && Password.equals("123")) {//这个字符串将会在js中被接收//1代表登录成功//2代表用户名或密码为空//3代表用户名或密码错误out.write("1");}else if(User==""||Password==""){out.write("2");}else {out.write("3");}out.close();}}