From 48962fa88c3a988b2f20a7ccba6424d037e16f0b Mon Sep 17 00:00:00 2001 From: wlf <920607690@qq.com> Date: Sat, 12 Jan 2019 12:17:28 +0800 Subject: [PATCH 01/10] Merge remote-tracking branch 'remotes/origin/master' into wlf # Conflicts: # src/core/process/Process.java --- src/servlet/account/S_Register.java | 37 +++++++++++++++++++++++++++-- src/servlet/account/login.java | 2 -- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/servlet/account/S_Register.java b/src/servlet/account/S_Register.java index f0f7077..077cfa0 100644 --- a/src/servlet/account/S_Register.java +++ b/src/servlet/account/S_Register.java @@ -1,4 +1,37 @@ package servlet.account; -public class S_Register { -} +import core.user.User; +import core.user.utils.AccountManagement; +import error.GExcptSQL; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class S_Register extends HttpServlet { + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException { + super.doPost(request, resp); + Map user_info=new HashMap<>(); + String id=request.getParameter("id"); + user_info.put("id",id); + String name=request.getParameter("name"); + user_info.put("name",name); + String e_mail=request.getParameter("e-mail"); + user_info.put("e-mail",e_mail); + String phone_number=request.getParameter("phone-number"); + user_info.put("phone-number",phone_number); + String password=request.getParameter("password"); + user_info.put("password",password); + User user=null; + try { + user = AccountManagement.register("student",user_info); + } catch (GExcptSQL gExcptSQL) { + gExcptSQL.printStackTrace(); + } + + } +} \ No newline at end of file diff --git a/src/servlet/account/login.java b/src/servlet/account/login.java index 8da38bd..ed9b178 100644 --- a/src/servlet/account/login.java +++ b/src/servlet/account/login.java @@ -2,13 +2,11 @@ package servlet.account; import java.io.IOException; import java.sql.SQLException; - import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import core.user.Student; import core.user.User; import core.user.utils.AccountManagement; From 8db98cedfb64d442e3fe66ff9dda94f8ad02f53c Mon Sep 17 00:00:00 2001 From: wlf <920607690@qq.com> Date: Sat, 12 Jan 2019 12:22:54 +0800 Subject: [PATCH 02/10] Merge remote-tracking branch 'remotes/origin/master' into wlf # Conflicts: # src/core/process/Process.java --- src/servlet/account/S_Register.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/servlet/account/S_Register.java b/src/servlet/account/S_Register.java index 077cfa0..d19d6e0 100644 --- a/src/servlet/account/S_Register.java +++ b/src/servlet/account/S_Register.java @@ -21,9 +21,9 @@ public class S_Register extends HttpServlet { String name=request.getParameter("name"); user_info.put("name",name); String e_mail=request.getParameter("e-mail"); - user_info.put("e-mail",e_mail); + user_info.put("e_mail",e_mail); String phone_number=request.getParameter("phone-number"); - user_info.put("phone-number",phone_number); + user_info.put("phone_number",phone_number); String password=request.getParameter("password"); user_info.put("password",password); User user=null; From 1d70584bf1b78bd82d8aa58baee6326424e049ae Mon Sep 17 00:00:00 2001 From: wlf <920607690@qq.com> Date: Sat, 12 Jan 2019 12:37:18 +0800 Subject: [PATCH 03/10] Merge remote-tracking branch 'remotes/origin/master' into wlf # Conflicts: # src/core/process/Process.java --- src/servlet/account/S_Register.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/servlet/account/S_Register.java b/src/servlet/account/S_Register.java index d19d6e0..cbec93b 100644 --- a/src/servlet/account/S_Register.java +++ b/src/servlet/account/S_Register.java @@ -13,8 +13,8 @@ import java.util.Map; public class S_Register extends HttpServlet { @Override - protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException { - super.doPost(request, resp); + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + super.doPost(request, response); Map user_info=new HashMap<>(); String id=request.getParameter("id"); user_info.put("id",id); @@ -32,6 +32,8 @@ public class S_Register extends HttpServlet { } catch (GExcptSQL gExcptSQL) { gExcptSQL.printStackTrace(); } + request.getSession().setAttribute("User",user); + request.getRequestDispatcher("/login.jsp").forward(request,response); } } \ No newline at end of file From 1f5b0b6f7ab370c646a2a8c812e7c4ee31b9c774 Mon Sep 17 00:00:00 2001 From: wlf <920607690@qq.com> Date: Sat, 12 Jan 2019 12:50:06 +0800 Subject: [PATCH 04/10] Merge remote-tracking branch 'remotes/origin/master' into wlf # Conflicts: # src/core/process/Process.java --- GDMS.iml | 4 ++-- src/servlet/account/S_Register.java | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/GDMS.iml b/GDMS.iml index 0ccb429..34d2f99 100644 --- a/GDMS.iml +++ b/GDMS.iml @@ -19,11 +19,11 @@ - + - + diff --git a/src/servlet/account/S_Register.java b/src/servlet/account/S_Register.java index cbec93b..20d558c 100644 --- a/src/servlet/account/S_Register.java +++ b/src/servlet/account/S_Register.java @@ -32,8 +32,6 @@ public class S_Register extends HttpServlet { } catch (GExcptSQL gExcptSQL) { gExcptSQL.printStackTrace(); } - request.getSession().setAttribute("User",user); request.getRequestDispatcher("/login.jsp").forward(request,response); - } } \ No newline at end of file From ad054fde4bfc5ddda9002058bc289b381be83d54 Mon Sep 17 00:00:00 2001 From: wlf <920607690@qq.com> Date: Sat, 12 Jan 2019 12:50:23 +0800 Subject: [PATCH 05/10] Merge remote-tracking branch 'remotes/origin/master' into wlf # Conflicts: # src/core/process/Process.java --- src/servlet/account/S_Register.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/servlet/account/S_Register.java b/src/servlet/account/S_Register.java index 20d558c..cbec93b 100644 --- a/src/servlet/account/S_Register.java +++ b/src/servlet/account/S_Register.java @@ -32,6 +32,8 @@ public class S_Register extends HttpServlet { } catch (GExcptSQL gExcptSQL) { gExcptSQL.printStackTrace(); } + request.getSession().setAttribute("User",user); request.getRequestDispatcher("/login.jsp").forward(request,response); + } } \ No newline at end of file From 62759d6b34300624a59ed2d89e263b8e11fa2f9f Mon Sep 17 00:00:00 2001 From: wlf <920607690@qq.com> Date: Sat, 12 Jan 2019 12:54:27 +0800 Subject: [PATCH 06/10] Merge remote-tracking branch 'remotes/origin/master' into wlf # Conflicts: # src/core/process/Process.java --- src/servlet/account/S_Register.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/servlet/account/S_Register.java b/src/servlet/account/S_Register.java index cbec93b..3a82a6e 100644 --- a/src/servlet/account/S_Register.java +++ b/src/servlet/account/S_Register.java @@ -33,7 +33,7 @@ public class S_Register extends HttpServlet { gExcptSQL.printStackTrace(); } request.getSession().setAttribute("User",user); - request.getRequestDispatcher("/login.jsp").forward(request,response); + request.getRequestDispatcher("/home.jsp").forward(request,response); } } \ No newline at end of file From 86fbf1db1baa2002e1cf184bc67247af87fb2cc5 Mon Sep 17 00:00:00 2001 From: wlf <920607690@qq.com> Date: Sat, 12 Jan 2019 15:45:28 +0800 Subject: [PATCH 07/10] Merge remote-tracking branch 'remotes/origin/master' into wlf # Conflicts: # src/core/process/Process.java --- src/servlet/basic_settings/S_Filter.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/servlet/basic_settings/S_Filter.java diff --git a/src/servlet/basic_settings/S_Filter.java b/src/servlet/basic_settings/S_Filter.java new file mode 100644 index 0000000..b8144e1 --- /dev/null +++ b/src/servlet/basic_settings/S_Filter.java @@ -0,0 +1,17 @@ +package servlet.basic_settings; + +import javax.servlet.*; +import java.io.IOException; + +public class S_Filter implements Filter { + + public void init(FilterConfig filterConfig) throws ServletException { + + } + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + + } + public void destory(){ + + } +} From 881abc033acc0672b70255afc76bc23b27dd96fe Mon Sep 17 00:00:00 2001 From: wlf <920607690@qq.com> Date: Sat, 12 Jan 2019 15:46:36 +0800 Subject: [PATCH 08/10] Merge remote-tracking branch 'remotes/origin/master' into wlf # Conflicts: # src/core/process/Process.java --- src/servlet/S_TeaccherSelectStudent.java | 4 ++++ src/servlet/account/S_Register.java | 1 + src/servlet/basic_settings/S_Listener.java | 4 ++++ web/select.jsp | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/servlet/S_TeaccherSelectStudent.java create mode 100644 src/servlet/basic_settings/S_Listener.java diff --git a/src/servlet/S_TeaccherSelectStudent.java b/src/servlet/S_TeaccherSelectStudent.java new file mode 100644 index 0000000..1a1cf25 --- /dev/null +++ b/src/servlet/S_TeaccherSelectStudent.java @@ -0,0 +1,4 @@ +package servlet; + +public class S_TeaccherSelectStudent { +} diff --git a/src/servlet/account/S_Register.java b/src/servlet/account/S_Register.java index 3a82a6e..6dcef13 100644 --- a/src/servlet/account/S_Register.java +++ b/src/servlet/account/S_Register.java @@ -32,6 +32,7 @@ public class S_Register extends HttpServlet { } catch (GExcptSQL gExcptSQL) { gExcptSQL.printStackTrace(); } + //注册失败 request.getSession().setAttribute("User",user); request.getRequestDispatcher("/home.jsp").forward(request,response); diff --git a/src/servlet/basic_settings/S_Listener.java b/src/servlet/basic_settings/S_Listener.java new file mode 100644 index 0000000..84b0026 --- /dev/null +++ b/src/servlet/basic_settings/S_Listener.java @@ -0,0 +1,4 @@ +package servlet.basic_settings; + +public class S_Listener { +} diff --git a/web/select.jsp b/web/select.jsp index d214f7b..640a15f 100644 --- a/web/select.jsp +++ b/web/select.jsp @@ -25,7 +25,7 @@
-
+
c
李先生
From c6330cb71c94b8af59d73bb56873df08827ebe50 Mon Sep 17 00:00:00 2001 From: wlf <920607690@qq.com> Date: Sat, 12 Jan 2019 22:37:32 +0800 Subject: [PATCH 09/10] Merge branch 'master' of https://bdgit.educoder.net/zhailw/gdms into wlf # Conflicts: # GDMS.iml # src/servlet/account/login.java --- GDMS.iml | 4 +- src/servlet/S_TeaccherSelectStudent.java | 4 -- src/servlet/S_TeacherSelectStudent.java | 19 ++++++++++ src/servlet/account/S_Register.java | 6 +++ src/servlet/basic_settings/S_Filter.java | 48 +++++++++++++++++++++--- web/login.jsp | 2 +- 6 files changed, 70 insertions(+), 13 deletions(-) delete mode 100644 src/servlet/S_TeaccherSelectStudent.java create mode 100644 src/servlet/S_TeacherSelectStudent.java diff --git a/GDMS.iml b/GDMS.iml index 3a5c57b..34d2f99 100644 --- a/GDMS.iml +++ b/GDMS.iml @@ -19,15 +19,15 @@ + - + - \ No newline at end of file diff --git a/src/servlet/S_TeaccherSelectStudent.java b/src/servlet/S_TeaccherSelectStudent.java deleted file mode 100644 index 1a1cf25..0000000 --- a/src/servlet/S_TeaccherSelectStudent.java +++ /dev/null @@ -1,4 +0,0 @@ -package servlet; - -public class S_TeaccherSelectStudent { -} diff --git a/src/servlet/S_TeacherSelectStudent.java b/src/servlet/S_TeacherSelectStudent.java new file mode 100644 index 0000000..71e0c42 --- /dev/null +++ b/src/servlet/S_TeacherSelectStudent.java @@ -0,0 +1,19 @@ +package servlet; + +import core.user.User; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class S_TeacherSelectStudent extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + super.doPost(request, response); + String teacher_id=request.getParameter("id"); + User user=(User)request.getSession().getAttribute("User"); + String student_id=user.getId(); + + } +} diff --git a/src/servlet/account/S_Register.java b/src/servlet/account/S_Register.java index 6dcef13..b3397fb 100644 --- a/src/servlet/account/S_Register.java +++ b/src/servlet/account/S_Register.java @@ -2,12 +2,14 @@ package servlet.account; import core.user.User; import core.user.utils.AccountManagement; +import error.GExcptAccount; import error.GExcptSQL; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.sql.SQLException; import java.util.HashMap; import java.util.Map; @@ -31,6 +33,10 @@ public class S_Register extends HttpServlet { user = AccountManagement.register("student",user_info); } catch (GExcptSQL gExcptSQL) { gExcptSQL.printStackTrace(); + } catch (GExcptAccount gExcptAccount) { + gExcptAccount.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); } //注册失败 request.getSession().setAttribute("User",user); diff --git a/src/servlet/basic_settings/S_Filter.java b/src/servlet/basic_settings/S_Filter.java index b8144e1..610ec49 100644 --- a/src/servlet/basic_settings/S_Filter.java +++ b/src/servlet/basic_settings/S_Filter.java @@ -1,17 +1,53 @@ package servlet.basic_settings; import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import java.io.IOException; - +@WebFilter(filterName = "sessionFilter",urlPatterns = {"/*"}) public class S_Filter implements Filter { + String NO_LOGIN="/notLogin"; + String[] includeUrls=new String[]{"redirect:http://localhost:8080/firstproject/demo/Front-end/Login/Login.html","redirect:http://localhost:8080/firstproject/demo/Front-end/Login/Login1.html"}; + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws ServletException,IOException{ + HttpServletRequest request=(HttpServletRequest) servletRequest; + HttpServletResponse response=(HttpServletResponse) servletResponse; + HttpSession session=request.getSession(false); + String uri=request.getRequestURI(); + //是否需要过滤 + boolean needFilter=isNeedFilter(uri); + if(!needFilter){ + filterChain.doFilter(servletRequest,servletResponse); + }else{ + //需要过滤器 + //session中包含user对象,则是登录状态 + if(session!=null&&session.getAttribute("user")!=null){ + filterChain.doFilter(servletRequest,servletResponse); + }else{ + String requestType=request.getHeader("X-Requested-with"); + //判断是否是ajax请求 + if(requestType!=null&&"XMLHttpRequest".equals(requestType)){ + response.sendRedirect(NO_LOGIN); + }else{ + //重定向到登录页(需要在static文件夹下建立此html文件) + response.sendRedirect(request.getContextPath()+"redirect:http://localhost:8080/firstproject/demo/Front-end/Login/Login.html"); + } + return; + } + } - public void init(FilterConfig filterConfig) throws ServletException { } - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { - + public boolean isNeedFilter(String uri) { + for (String includeUrl : includeUrls) { + if (includeUrl.equals(uri)) { + return false; + } + } + return true; } - public void destory(){ - } + } diff --git a/web/login.jsp b/web/login.jsp index 82983d5..92fda2b 100644 --- a/web/login.jsp +++ b/web/login.jsp @@ -56,7 +56,7 @@ From 1689e395451dcd2b0f94bd93ff21e14fd5778654 Mon Sep 17 00:00:00 2001 From: wlf <920607690@qq.com> Date: Sat, 12 Jan 2019 22:51:07 +0800 Subject: [PATCH 10/10] Merge branch 'master' of https://bdgit.educoder.net/zhailw/gdms into wlf # Conflicts: # GDMS.iml # src/servlet/account/login.java --- .idea/artifacts/GDMS_war_exploded.xml | 3 +++ src/servlet/S_TeacherSelectStudent.java | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.idea/artifacts/GDMS_war_exploded.xml b/.idea/artifacts/GDMS_war_exploded.xml index 6b1fe0c..12d7fe5 100644 --- a/.idea/artifacts/GDMS_war_exploded.xml +++ b/.idea/artifacts/GDMS_war_exploded.xml @@ -7,6 +7,9 @@ + + + diff --git a/src/servlet/S_TeacherSelectStudent.java b/src/servlet/S_TeacherSelectStudent.java index 71e0c42..1ebed38 100644 --- a/src/servlet/S_TeacherSelectStudent.java +++ b/src/servlet/S_TeacherSelectStudent.java @@ -1,5 +1,6 @@ package servlet; +import core.process.C_TeacherSelectStudent; import core.user.User; import javax.servlet.ServletException; @@ -14,6 +15,10 @@ public class S_TeacherSelectStudent extends HttpServlet { String teacher_id=request.getParameter("id"); User user=(User)request.getSession().getAttribute("User"); String student_id=user.getId(); - + try { + new C_TeacherSelectStudent().select(teacher_id,student_id); + } catch (Exception e) { + e.printStackTrace(); + } } }