From f1a42895bfa390ca1a9374b82513ecf7f292383a Mon Sep 17 00:00:00 2001 From: Qing Date: Wed, 7 Jun 2023 00:10:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Axios=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../landaiqing/filter/UserSessionFilter.java | 2 +- .../landaiqing/servlet/ExUserNameServlet.java | 42 +++++++++++++++++++ web/register.jsp | 27 ++++++++++-- 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 src/com/landaiqing/servlet/ExUserNameServlet.java diff --git a/src/com/landaiqing/filter/UserSessionFilter.java b/src/com/landaiqing/filter/UserSessionFilter.java index f24edf1..3b8f191 100644 --- a/src/com/landaiqing/filter/UserSessionFilter.java +++ b/src/com/landaiqing/filter/UserSessionFilter.java @@ -19,7 +19,7 @@ import java.io.IOException; */ @WebFilter("/*")// 过滤器所有的请求 public class UserSessionFilter implements Filter { - private String[] excludeUrls = new String[]{"/login", "/register", "/VerifycodeServlet"}; + private String[] excludeUrls = new String[]{"/login", "/register", "/VerifycodeServlet","/ExUserNameServlet"}; @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { diff --git a/src/com/landaiqing/servlet/ExUserNameServlet.java b/src/com/landaiqing/servlet/ExUserNameServlet.java new file mode 100644 index 0000000..3377daf --- /dev/null +++ b/src/com/landaiqing/servlet/ExUserNameServlet.java @@ -0,0 +1,42 @@ +package com.landaiqing.servlet; + + +import com.landaiqing.entity.UserEntity; +import com.landaiqing.service.UserService; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; +import java.io.PrintWriter; + +/** + * http://localhost:8080/mayikt_session_war_exploded/exUserNameServlet?name=1 + * @author 余胜军 + * @ClassName ExUserNameServlet + * @qq 644064779 + * @addres www.mayikt.com + * 微信:yushengjun644 + */ +@WebServlet("/exUserNameServlet") +public class ExUserNameServlet extends HttpServlet { + + private UserService UserService = new UserService(); + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("text/html;charset=utf-8"); + //1.获取到用户输入的userName参数值 + String userName = req.getParameter("userName"); + //2.调用数据库根据userName查询用户名称是否存在 + UserEntity mayiktUserEntity = UserService.findByUserName(userName); + PrintWriter writer = resp.getWriter(); + if (mayiktUserEntity != null) { + writer.print("该用户" + userName + "已经存在的 无法注册!"); + } + writer.close(); + } +} + diff --git a/web/register.jsp b/web/register.jsp index 23e7c9e..ab014f1 100644 --- a/web/register.jsp +++ b/web/register.jsp @@ -10,12 +10,12 @@ 注册页面 -
-
+ +

看不清?换一张图片
- ${errorMsg} + ${errorMsg}
+ + \ No newline at end of file