From 253934353738eb86d76a8c98f1878b2a2859957b Mon Sep 17 00:00:00 2001
From: Huierw <1021432804@qq.com>
Date: Thu, 11 Mar 2021 19:26:03 +0800
Subject: [PATCH 01/15] =?UTF-8?q?update=20README.md.=20=E7=AC=AC=E4=B8=80?=
=?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A-=E4=BF=AE=E6=94=B9readme=E6=96=87?=
=?UTF-8?q?=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index c4520c6..f1d0c8d 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@
#### 完成内容列表
1. 搭建环境
-2. xxxx
+2. 完成修改
3. xxxx
4. xxxx
--
Gitee
From 9982a5ca33b637f92eefc35a407035f0f75cca2b Mon Sep 17 00:00:00 2001
From: lijunhui <1021432804@qq.com>
Date: Fri, 19 Mar 2021 17:05:19 +0800
Subject: [PATCH 02/15] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=9F=BA=E7=A1=80?=
=?UTF-8?q?=E7=9A=84=E7=99=BB=E5=BD=95=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/pom.xml | 54 +++++++++++++++++++
com/src/main/java/LoginServlet.java | 28 ++++++++++
com/src/main/java/Service.java | 49 +++++++++++++++++
com/src/main/java/User.java | 20 +++++++
com/src/main/webapp/WEB-INF/web.xml | 15 ++++++
com/src/main/webapp/index.jsp | 35 ++++++++++++
com/src/main/webapp/main.jsp | 20 +++++++
.../com-1.0-SNAPSHOT/META-INF/MANIFEST.MF | 5 ++
com/target/com-1.0-SNAPSHOT/WEB-INF/web.xml | 15 ++++++
com/target/com-1.0-SNAPSHOT/index.jsp | 35 ++++++++++++
com/target/com-1.0-SNAPSHOT/main.jsp | 20 +++++++
11 files changed, 296 insertions(+)
create mode 100644 com/pom.xml
create mode 100644 com/src/main/java/LoginServlet.java
create mode 100644 com/src/main/java/Service.java
create mode 100644 com/src/main/java/User.java
create mode 100644 com/src/main/webapp/WEB-INF/web.xml
create mode 100644 com/src/main/webapp/index.jsp
create mode 100644 com/src/main/webapp/main.jsp
create mode 100644 com/target/com-1.0-SNAPSHOT/META-INF/MANIFEST.MF
create mode 100644 com/target/com-1.0-SNAPSHOT/WEB-INF/web.xml
create mode 100644 com/target/com-1.0-SNAPSHOT/index.jsp
create mode 100644 com/target/com-1.0-SNAPSHOT/main.jsp
diff --git a/com/pom.xml b/com/pom.xml
new file mode 100644
index 0000000..a49a9f5
--- /dev/null
+++ b/com/pom.xml
@@ -0,0 +1,54 @@
+
+
+ 4.0.0
+
+ com.example
+ com
+ 1.0-SNAPSHOT
+ com
+ war
+
+
+ 1.8
+ 1.8
+ 5.7.0
+
+
+
+
+ javax
+ javaee-api
+ 8.0.1
+ provided
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ ${junit.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit.version}
+ test
+
+
+ mysql
+ mysql-connector-java
+ 8.0.11
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ 3.3.0
+
+
+
+
\ No newline at end of file
diff --git a/com/src/main/java/LoginServlet.java b/com/src/main/java/LoginServlet.java
new file mode 100644
index 0000000..0e1053a
--- /dev/null
+++ b/com/src/main/java/LoginServlet.java
@@ -0,0 +1,28 @@
+import javax.servlet.http.*;
+import java.io.*;
+import javax.servlet.*;
+
+public class LoginServlet extends HttpServlet {
+
+ protected void doPost(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException
+ {
+ response.setContentType("text/html;charset=gb2312");
+ request.setCharacterEncoding("utf-8");
+ User u = new User();
+ u.setUsername(request.getParameter("username"));
+ u.setPassword(request.getParameter("password"));
+ request.setAttribute("", u);
+ boolean falg = Service.assertUser(u);
+ if(falg){
+ request.getRequestDispatcher("/main.jsp").forward(request,response);
+ }else{
+ response.sendRedirect("./index.jsp");
+ }
+
+ }
+
+
+}
+
+
diff --git a/com/src/main/java/Service.java b/com/src/main/java/Service.java
new file mode 100644
index 0000000..e779b88
--- /dev/null
+++ b/com/src/main/java/Service.java
@@ -0,0 +1,49 @@
+import java.sql.*;
+
+
+public class Service {
+ public static boolean assertUser(User u){
+ // TODO Auto-generated method stub
+ boolean flag = false;
+ try {
+
+ //加载驱动程序
+ Class.forName("com.mysql.cj.jdbc.Driver");
+
+ //创建连接
+ String url="jdbc:mysql://localhost:3306/javaee?serverTimezone=GMT&useSSL=false&allowPublicKeyRetrieval=true";
+ String username="root";
+ String pwd ="root";
+ Connection conn = DriverManager.getConnection(url,username,pwd);
+
+ //创建Statement,执行sql
+ Statement st=conn.createStatement();
+ String sql = "select * from user where username = '"+u.getUsername()+"' ";
+ ResultSet rs =st.executeQuery(sql);
+
+ if(rs.getString("password")!=u.getPassword()){
+ flag = false;
+ }else{
+ flag = true;
+ }
+
+
+ //关闭连接
+ rs.close();
+ st.close();
+ conn.close();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return flag;
+ }
+
+
+
+
+}
diff --git a/com/src/main/java/User.java b/com/src/main/java/User.java
new file mode 100644
index 0000000..a80078e
--- /dev/null
+++ b/com/src/main/java/User.java
@@ -0,0 +1,20 @@
+public class User {
+ private String username;
+ private String password;
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
diff --git a/com/src/main/webapp/WEB-INF/web.xml b/com/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..3725c59
--- /dev/null
+++ b/com/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,15 @@
+
+
+
+
+ LoginServlet
+ LoginServlet
+
+
+ LoginServlet
+ /loginAction
+
+
\ No newline at end of file
diff --git a/com/src/main/webapp/index.jsp b/com/src/main/webapp/index.jsp
new file mode 100644
index 0000000..7edddc3
--- /dev/null
+++ b/com/src/main/webapp/index.jsp
@@ -0,0 +1,35 @@
+<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
+
+
+
+ JSP - Hello World
+
+
+<%= "Hello World!" %>
+
+
+Login JSP
+
+
+
+
\ No newline at end of file
diff --git a/com/src/main/webapp/main.jsp b/com/src/main/webapp/main.jsp
new file mode 100644
index 0000000..2d4e943
--- /dev/null
+++ b/com/src/main/webapp/main.jsp
@@ -0,0 +1,20 @@
+<%--
+ Created by IntelliJ IDEA.
+ User: lijunhui
+ Date: 3/18/2021
+ Time: 11:00 AM
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ Main
+
+
+
+ - Hello ${sessionScope.u.username}
+
+
+
+
+
diff --git a/com/target/com-1.0-SNAPSHOT/META-INF/MANIFEST.MF b/com/target/com-1.0-SNAPSHOT/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5168ab5
--- /dev/null
+++ b/com/target/com-1.0-SNAPSHOT/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Created-By: IntelliJ IDEA
+Built-By: lijunhui
+Build-Jdk: version 15.0.1
+
diff --git a/com/target/com-1.0-SNAPSHOT/WEB-INF/web.xml b/com/target/com-1.0-SNAPSHOT/WEB-INF/web.xml
new file mode 100644
index 0000000..3725c59
--- /dev/null
+++ b/com/target/com-1.0-SNAPSHOT/WEB-INF/web.xml
@@ -0,0 +1,15 @@
+
+
+
+
+ LoginServlet
+ LoginServlet
+
+
+ LoginServlet
+ /loginAction
+
+
\ No newline at end of file
diff --git a/com/target/com-1.0-SNAPSHOT/index.jsp b/com/target/com-1.0-SNAPSHOT/index.jsp
new file mode 100644
index 0000000..7edddc3
--- /dev/null
+++ b/com/target/com-1.0-SNAPSHOT/index.jsp
@@ -0,0 +1,35 @@
+<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
+
+
+
+ JSP - Hello World
+
+
+<%= "Hello World!" %>
+
+
+Login JSP
+
+
+
+
\ No newline at end of file
diff --git a/com/target/com-1.0-SNAPSHOT/main.jsp b/com/target/com-1.0-SNAPSHOT/main.jsp
new file mode 100644
index 0000000..2d4e943
--- /dev/null
+++ b/com/target/com-1.0-SNAPSHOT/main.jsp
@@ -0,0 +1,20 @@
+<%--
+ Created by IntelliJ IDEA.
+ User: lijunhui
+ Date: 3/18/2021
+ Time: 11:00 AM
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ Main
+
+
+
+ - Hello ${sessionScope.u.username}
+
+
+
+
+
--
Gitee
From 49822bfb4714c0b5bc0f86b15feda1108b1cc23e Mon Sep 17 00:00:00 2001
From: lijunhui <1021432804@qq.com>
Date: Fri, 19 Mar 2021 17:48:59 +0800
Subject: [PATCH 03/15] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E6=9B=B4=E7=BB=99?=
=?UTF-8?q?=E6=8F=90=E4=BA=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/src/main/webapp/WEB-INF/web.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/com/src/main/webapp/WEB-INF/web.xml b/com/src/main/webapp/WEB-INF/web.xml
index 3725c59..a7db993 100644
--- a/com/src/main/webapp/WEB-INF/web.xml
+++ b/com/src/main/webapp/WEB-INF/web.xml
@@ -6,7 +6,7 @@
LoginServlet
- LoginServlet
+ javaLoginServlet
LoginServlet
--
Gitee
From 971efce671d41b57f28b65aa5d5e99b5434a8b48 Mon Sep 17 00:00:00 2001
From: lijunhui <1021432804@qq.com>
Date: Fri, 19 Mar 2021 17:56:30 +0800
Subject: [PATCH 04/15] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E6=9B=B4=E7=BB=99?=
=?UTF-8?q?=E6=8F=90=E4=BA=A42?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/src/main/webapp/WEB-INF/web.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/com/src/main/webapp/WEB-INF/web.xml b/com/src/main/webapp/WEB-INF/web.xml
index a7db993..3725c59 100644
--- a/com/src/main/webapp/WEB-INF/web.xml
+++ b/com/src/main/webapp/WEB-INF/web.xml
@@ -6,7 +6,7 @@
LoginServlet
- javaLoginServlet
+ LoginServlet
LoginServlet
--
Gitee
From 09c1eeccb984548d6d3eafaad5bd2bb09b5a2bb5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=90=9B=E6=85=A7?= <1021432804@qq.com>
Date: Sun, 21 Mar 2021 17:01:21 +0800
Subject: [PATCH 05/15] =?UTF-8?q?update=20com/src/main/java/Service.java.?=
=?UTF-8?q?=20=E6=95=B0=E6=8D=AE=E5=BA=93=E6=9F=A5=E8=AF=A2=E9=82=A3?=
=?UTF-8?q?=E9=87=8C=E5=A4=84=E7=90=86bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/src/main/java/Service.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/com/src/main/java/Service.java b/com/src/main/java/Service.java
index e779b88..b142063 100644
--- a/com/src/main/java/Service.java
+++ b/com/src/main/java/Service.java
@@ -21,10 +21,12 @@ public class Service {
String sql = "select * from user where username = '"+u.getUsername()+"' ";
ResultSet rs =st.executeQuery(sql);
- if(rs.getString("password")!=u.getPassword()){
+ while(rs.next()){
+ if(rs.getString("password")!=u.getPassword()){
flag = false;
- }else{
+ }else{
flag = true;
+ }
}
--
Gitee
From 6d2b2f935aa19361319515637ec705536a7be109 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=90=9B=E6=85=A7?= <1021432804@qq.com>
Date: Mon, 22 Mar 2021 20:03:45 +0800
Subject: [PATCH 06/15] =?UTF-8?q?update=20com/src/main/java/Service.java.?=
=?UTF-8?q?=20sql=E6=9F=A5=E8=AF=A2=E5=87=BA=E6=9D=A5=E7=9A=84=E5=AD=97?=
=?UTF-8?q?=E7=AC=A6=E4=B8=B2=E5=A4=84=E7=90=86=E6=9C=89=E9=97=AE=E9=A2=98?=
=?UTF-8?q?=EF=BC=8C=E4=BB=8A=E5=A4=A9=E6=9B=B4=E6=94=B9=E4=BA=86=E4=B8=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/src/main/java/Service.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/com/src/main/java/Service.java b/com/src/main/java/Service.java
index b142063..2de1ecf 100644
--- a/com/src/main/java/Service.java
+++ b/com/src/main/java/Service.java
@@ -22,10 +22,10 @@ public class Service {
ResultSet rs =st.executeQuery(sql);
while(rs.next()){
- if(rs.getString("password")!=u.getPassword()){
- flag = false;
+ if(rs.getString("password").equals(u.getPassword())){
+ flag = true;
}else{
- flag = true;
+ flag = false;
}
}
--
Gitee
From 1c8013ab2aa076062081e2a66875487ef30d540d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=90=9B=E6=85=A7?= <1021432804@qq.com>
Date: Mon, 22 Mar 2021 21:06:40 +0800
Subject: [PATCH 07/15] =?UTF-8?q?add=20com/src/main/java/LoginFilter.=20?=
=?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=87=E6=BB=A4=E5=99=A8=E7=9A=84java?=
=?UTF-8?q?=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/src/main/java/LoginFilter | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 com/src/main/java/LoginFilter
diff --git a/com/src/main/java/LoginFilter b/com/src/main/java/LoginFilter
new file mode 100644
index 0000000..2d540f4
--- /dev/null
+++ b/com/src/main/java/LoginFilter
@@ -0,0 +1,35 @@
+import java.io.IOException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+
+public class LoginFilter implements Filter {
+
+ public void doFilter(ServletRequest request,
+ ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ HttpServletRequest hrequest = (HttpServletRequest)request;
+ HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper((HttpServletResponse) response);
+ String user = ( String ) hrequest.getSession().getAttribute("username");//判断用户是否登录
+
+ if (hrequest.getRequestURI().contains("index")) {
+ // 对登录页面不进行过滤
+ chain.doFilter(request, response);
+ return;
+ }
+
+ if (user == null) {
+ wrapper.sendRedirect("index.jsp");
+ return;
+ }else {
+ chain.doFilter(request, response);
+ return;
+ }
+ }
+}
--
Gitee
From a0151a6cb3ebc129f820541858a6edc4670957e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=90=9B=E6=85=A7?= <1021432804@qq.com>
Date: Mon, 22 Mar 2021 21:08:27 +0800
Subject: [PATCH 08/15] to com/src/main/java/LoginFilter.java.
---
com/src/main/java/{LoginFilter => LoginFilter.java} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename com/src/main/java/{LoginFilter => LoginFilter.java} (100%)
diff --git a/com/src/main/java/LoginFilter b/com/src/main/java/LoginFilter.java
similarity index 100%
rename from com/src/main/java/LoginFilter
rename to com/src/main/java/LoginFilter.java
--
Gitee
From 4078be250512e86000f14a4157ef2bcb82e5382e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=90=9B=E6=85=A7?= <1021432804@qq.com>
Date: Mon, 22 Mar 2021 21:11:10 +0800
Subject: [PATCH 09/15] =?UTF-8?q?update=20com/src/main/webapp/WEB-INF/web.?=
=?UTF-8?q?xml.=20=E5=A2=9E=E5=8A=A0web.xml=20=E9=87=8C=E7=9A=84filter?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/src/main/webapp/WEB-INF/web.xml | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/com/src/main/webapp/WEB-INF/web.xml b/com/src/main/webapp/WEB-INF/web.xml
index 3725c59..e54c898 100644
--- a/com/src/main/webapp/WEB-INF/web.xml
+++ b/com/src/main/webapp/WEB-INF/web.xml
@@ -12,4 +12,12 @@
LoginServlet
/loginAction
+
+ SessionFilter
+ LoginFilter
+
+
+ SessionFilter
+ /*
+
\ No newline at end of file
--
Gitee
From a8b908c5c333cefc4172bb8aabbaf51938dde7f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=90=9B=E6=85=A7?= <1021432804@qq.com>
Date: Sat, 27 Mar 2021 15:43:59 +0800
Subject: [PATCH 10/15] =?UTF-8?q?update=20com/src/main/java/LoginFilter.ja?=
=?UTF-8?q?va.=20=E5=9B=A0=E4=B8=BA=E5=8E=9F=E6=9D=A5=E7=9A=84filter?=
=?UTF-8?q?=E5=92=8C=E6=96=B0=E4=BD=9C=E4=B8=9A=E7=9A=84Listener=E5=8F=91?=
=?UTF-8?q?=E7=94=9F=E9=97=AE=E9=A2=98=EF=BC=8C=E6=89=80=E4=BB=A5=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9=E4=BA=86=E4=B9=8B=E5=89=8D=E7=9A=84filter?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/src/main/java/LoginFilter.java | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/com/src/main/java/LoginFilter.java b/com/src/main/java/LoginFilter.java
index 2d540f4..20be22f 100644
--- a/com/src/main/java/LoginFilter.java
+++ b/com/src/main/java/LoginFilter.java
@@ -8,7 +8,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
-
public class LoginFilter implements Filter {
public void doFilter(ServletRequest request,
@@ -16,20 +15,25 @@ public class LoginFilter implements Filter {
FilterChain chain) throws IOException, ServletException {
HttpServletRequest hrequest = (HttpServletRequest)request;
HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper((HttpServletResponse) response);
- String user = ( String ) hrequest.getSession().getAttribute("username");//判断用户是否登录
+ String user = null;
+ if(hrequest.getSession(false) != null){
+ user = ( String ) hrequest.getSession(false).getAttribute("username");
+ }
if (hrequest.getRequestURI().contains("index")) {
// 对登录页面不进行过滤
chain.doFilter(request, response);
return;
}
- if (user == null) {
+ //判断用户是否登录
+ if (user == null & !(hrequest.getRequestURI().contains("login"))){
wrapper.sendRedirect("index.jsp");
return;
}else {
chain.doFilter(request, response);
return;
}
+
}
}
--
Gitee
From 048b7fbeb258e1880857af085de89bb85c7f3796 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=90=9B=E6=85=A7?= <1021432804@qq.com>
Date: Sat, 27 Mar 2021 15:45:35 +0800
Subject: [PATCH 11/15] =?UTF-8?q?add=20com/src/main/java/OnlineCont.java.?=
=?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=E5=9C=A8=E7=BA=BF=E4=BA=BA=E6=95=B0?=
=?UTF-8?q?=E7=BB=9F=E8=AE=A1=E7=9A=84Listener?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/src/main/java/OnlineCont.java | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 com/src/main/java/OnlineCont.java
diff --git a/com/src/main/java/OnlineCont.java b/com/src/main/java/OnlineCont.java
new file mode 100644
index 0000000..3430234
--- /dev/null
+++ b/com/src/main/java/OnlineCont.java
@@ -0,0 +1,23 @@
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+public class OnlineCont implements HttpSessionListener {
+ static int count=0;
+ static HttpSessionEvent se;
+
+ @Override
+ public void sessionCreated(HttpSessionEvent se) {
+ System.out.println("into sessionCreated");
+ count++;
+ se.getSession().getServletContext().setAttribute("count", count);
+
+ }
+
+ @Override
+ public synchronized void sessionDestroyed(HttpSessionEvent se) {
+ count--;
+ se.getSession().getServletContext().setAttribute("count", count);
+ }
+
+
+}
\ No newline at end of file
--
Gitee
From e5142d3dd25b5d0ce019da678b6b87f65ca5eef4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=90=9B=E6=85=A7?= <1021432804@qq.com>
Date: Sat, 27 Mar 2021 15:48:17 +0800
Subject: [PATCH 12/15] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?=
=?UTF-8?q?=E5=9C=A8=E7=BA=BF=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD=EF=BC=8C?=
=?UTF-8?q?=E5=BD=93=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E6=88=90=E5=8A=9F?=
=?UTF-8?q?=E5=90=8E=EF=BC=8C=E5=88=9B=E5=BB=BAsession=20=E6=AD=A4?=
=?UTF-8?q?=E5=A4=84=E8=AE=BE=E8=AE=A1=E4=B8=BA=E5=BD=93=E7=94=A8=E6=88=B7?=
=?UTF-8?q?=E5=AF=86=E7=A0=81=E8=BE=93=E5=85=A5=E6=88=90=E5=8A=9F=E6=97=B6?=
=?UTF-8?q?=E5=86=8D=E5=88=9B=E5=BB=BAsession?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/src/main/java/LoginServlet.java | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/com/src/main/java/LoginServlet.java b/com/src/main/java/LoginServlet.java
index 0e1053a..dcb0281 100644
--- a/com/src/main/java/LoginServlet.java
+++ b/com/src/main/java/LoginServlet.java
@@ -1,20 +1,28 @@
+import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;
+@WebServlet("/loginAction")
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
+
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("utf-8");
User u = new User();
u.setUsername(request.getParameter("username"));
u.setPassword(request.getParameter("password"));
- request.setAttribute("", u);
- boolean falg = Service.assertUser(u);
- if(falg){
+ request.setAttribute("user", u);
+
+ boolean flag = Service.assertUser(u);
+
+ if(flag){
+ // 判断用户登录成功,创建session
+ request.getSession();
+ request.setAttribute("count",OnlineCont.count);
request.getRequestDispatcher("/main.jsp").forward(request,response);
}else{
response.sendRedirect("./index.jsp");
@@ -22,6 +30,13 @@ public class LoginServlet extends HttpServlet {
}
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ request.getSession().invalidate();
+ response.sendRedirect("./index.jsp");
+ }
+}
}
--
Gitee
From f64e365abdd43a520b421fabdb39f89de5750a0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=90=9B=E6=85=A7?= <1021432804@qq.com>
Date: Sat, 27 Mar 2021 15:49:48 +0800
Subject: [PATCH 13/15] =?UTF-8?q?=E6=9B=B4=E6=94=B9=20page=20session=3D"fa?=
=?UTF-8?q?lse"=20session=3D"false"=EF=BC=8C=E6=8E=A7=E5=88=B6=E5=9C=A8?=
=?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=89=93=E5=BC=80=E6=97=B6=E5=80=99=E4=B8=8D?=
=?UTF-8?q?=E5=88=9B=E5=BB=BAsession?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
com/src/main/webapp/index.jsp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/com/src/main/webapp/index.jsp b/com/src/main/webapp/index.jsp
index 7edddc3..974e2d8 100644
--- a/com/src/main/webapp/index.jsp
+++ b/com/src/main/webapp/index.jsp
@@ -1,4 +1,4 @@
-<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
+<%@ page session="false" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
@@ -7,8 +7,10 @@
<%= "Hello World!" %>
+<%
+ HttpSession s = request.getSession(false);
+%>
-Login JSP