Skip to content

Commit 3ec63d3

Browse files
committed
网站在线用户信息、网站访问量以及管理踢出用户实例
1 parent 5c3d6b7 commit 3ec63d3

34 files changed

+674
-0
lines changed

myOnlinesWeb2/.classpath

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_6_CONTAINER"/>
6+
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
7+
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
8+
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
9+
</classpath>

myOnlinesWeb2/.mymetadata

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-module
3+
type="WEB"
4+
name="myOnlinesWeb2"
5+
id="myeclipse.1471662522385"
6+
context-root="/myOnlinesWeb2"
7+
j2ee-spec="6.0"
8+
archive="myOnlinesWeb2.war">
9+
<attributes>
10+
<attribute name="webrootdir" value="WebRoot" />
11+
</attributes>
12+
</project-module>
13+

myOnlinesWeb2/.project

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>myOnlinesWeb2</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.jdt.core.javabuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
<buildCommand>
29+
<name>com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator</name>
30+
<arguments>
31+
</arguments>
32+
</buildCommand>
33+
<buildCommand>
34+
<name>com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator</name>
35+
<arguments>
36+
</arguments>
37+
</buildCommand>
38+
<buildCommand>
39+
<name>org.eclipse.wst.validation.validationbuilder</name>
40+
<arguments>
41+
</arguments>
42+
</buildCommand>
43+
<buildCommand>
44+
<name>com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder</name>
45+
<arguments>
46+
</arguments>
47+
</buildCommand>
48+
</buildSpec>
49+
<natures>
50+
<nature>com.genuitec.eclipse.ast.deploy.core.deploymentnature</nature>
51+
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
52+
<nature>com.genuitec.eclipse.j2eedt.core.webnature</nature>
53+
<nature>org.eclipse.jdt.core.javanature</nature>
54+
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
55+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
56+
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
57+
</natures>
58+
</projectDescription>

myOnlinesWeb2/.settings/.jsdtscope

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="WebRoot"/>
4+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
6+
<attributes>
7+
<attribute name="hide" value="true"/>
8+
</attributes>
9+
</classpathentry>
10+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
11+
<classpathentry kind="output" path=""/>
12+
</classpath>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#Sat Aug 20 11:08:43 CST 2016
2+
eclipse.preferences.version=1
3+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5+
org.eclipse.jdt.core.compiler.compliance=1.6
6+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
7+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
8+
org.eclipse.jdt.core.compiler.source=1.6
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-modules id="moduleCoreId" project-version="1.5.0">
3+
<wb-module deploy-name="myOnlinesWeb2">
4+
<wb-resource deploy-path="/" source-path="/WebRoot"/>
5+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
6+
<property name="context-root" value="/myOnlinesWeb2"/>
7+
<property name="java-output-path" value="/myOnlinesWeb2/WebRoot/WEB-INF/classes"/>
8+
</wb-module>
9+
</project-modules>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<faceted-project>
3+
<fixed facet="wst.jsdt.web"/>
4+
<installed facet="java" version="1.6"/>
5+
<installed facet="jst.web" version="3.0"/>
6+
<installed facet="wst.jsdt.web" version="1.0"/>
7+
</faceted-project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Window

myOnlinesWeb2/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
这个稍微比上个版本做得完善了一点,用了JavaBean来封装用户信息,添加了一个管理踢用户的功能。
2+
上一个的用户访问量是通过监听request来统计的,在这个实例中,我们也可以通过过滤器来实现统计网站访问量。
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Class-Path:
3+
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

myOnlinesWeb2/WebRoot/WEB-INF/web.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="3.0"
3+
xmlns="http://java.sun.com/xml/ns/javaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
6+
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
7+
<display-name></display-name>
8+
9+
<listener>
10+
<listener-class>cn.hncu.listeners.MyServletContextListener</listener-class>
11+
</listener>
12+
<listener>
13+
<listener-class>cn.hncu.listeners.MySessionListener</listener-class>
14+
</listener>
15+
16+
<servlet>
17+
<servlet-name>LoginServlet</servlet-name>
18+
<servlet-class>cn.hncu.servlet.LoginServlet</servlet-class>
19+
</servlet>
20+
<servlet>
21+
<servlet-name>LogOutServlet</servlet-name>
22+
<servlet-class>cn.hncu.servlet.LogOutServlet</servlet-class>
23+
</servlet>
24+
<servlet>
25+
<servlet-name>ShowServlet</servlet-name>
26+
<servlet-class>cn.hncu.servlet.ShowServlet</servlet-class>
27+
</servlet>
28+
<servlet>
29+
<servlet-name>KickOutServlet</servlet-name>
30+
<servlet-class>cn.hncu.servlet.KickOutServlet</servlet-class>
31+
</servlet>
32+
33+
<servlet-mapping>
34+
<servlet-name>LoginServlet</servlet-name>
35+
<url-pattern>/LoginServlet</url-pattern>
36+
</servlet-mapping>
37+
<servlet-mapping>
38+
<servlet-name>LogOutServlet</servlet-name>
39+
<url-pattern>/servlet/LogOutServlet</url-pattern>
40+
</servlet-mapping>
41+
<servlet-mapping>
42+
<servlet-name>ShowServlet</servlet-name>
43+
<url-pattern>/servlet/ShowServlet</url-pattern>
44+
</servlet-mapping>
45+
<servlet-mapping>
46+
<servlet-name>KickOutServlet</servlet-name>
47+
<url-pattern>/servlet/KickOutServlet</url-pattern>
48+
</servlet-mapping>
49+
50+
<filter>
51+
<filter-name>charset</filter-name>
52+
<filter-class>cn.hncu.filter.CharsetFilter</filter-class>
53+
</filter>
54+
<filter>
55+
<filter-name>login</filter-name>
56+
<filter-class>cn.hncu.filter.LoginFilter</filter-class>
57+
</filter>
58+
59+
60+
<filter-mapping>
61+
<filter-name>login</filter-name>
62+
<url-pattern>/servlet/*</url-pattern>
63+
<url-pattern>/jsps/*</url-pattern>
64+
</filter-mapping>
65+
<filter-mapping>
66+
<filter-name>charset</filter-name>
67+
<url-pattern>/*</url-pattern>
68+
</filter-mapping>
69+
70+
<welcome-file-list>
71+
<welcome-file>index.jsp</welcome-file>
72+
</welcome-file-list>
73+
</web-app>

myOnlinesWeb2/WebRoot/index.jsp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2+
3+
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
4+
5+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
6+
<html>
7+
<head>
8+
<title>在线人信息管理与统计</title>
9+
</head>
10+
11+
<body>
12+
<h2>在线人信息管理与统计</h2>
13+
14+
<c:if test="${empty sessionScope.user}" var="boo">
15+
<h3>会员登录:</h3>
16+
<form action='<c:url value='/LoginServlet'></c:url>' method="post">
17+
姓名:<input type='text' name="name"><br /> <input type="submit"
18+
value="注册">
19+
</form>
20+
</c:if>
21+
22+
<c:if test="${!boo}">
23+
亲爱的${user.name}
24+
<c:if test="${user.admin}" var="bo">
25+
-管理员
26+
</c:if>
27+
<c:if test="${!bo}">
28+
-会员
29+
</c:if>
30+
,欢迎来到...<br />
31+
</c:if>
32+
33+
<br />
34+
<a href="<c:url value='/servlet/ShowServlet'/>">显示所有在线用户</a>
35+
<br />
36+
<a href="<c:url value='/servlet/LogOutServlet'/>">安全退出</a>
37+
38+
<br/>网站访问量:${count}
39+
40+
</body>
41+
</html>

myOnlinesWeb2/WebRoot/jsps/show.jsp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2+
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
3+
4+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5+
<html>
6+
<head>
7+
<title>在线人信息管理</title>
8+
<style type="text/css">
9+
table{
10+
border: 1px solid red;
11+
border-collapse: collapse;/*设置单线-线合并*/
12+
width: 80%;
13+
}
14+
td{
15+
border: 1px solid red;
16+
padding:3px;
17+
}
18+
.header{
19+
background: gray;
20+
}
21+
</style>
22+
</head>
23+
24+
<body>
25+
<h2>以下是所有在线用户信息</h2>
26+
<table>
27+
<tr class="header" >
28+
<td>姓名</td> <td>上线时间</td> <td>最后访问时间</td> <td>IP</td> <td>操作</td>
29+
</tr>
30+
31+
<c:forEach items="${requestScope.onLines}" var="map">
32+
<tr>
33+
<td>
34+
<c:if test="${empty map.user}" var="boo">
35+
游客
36+
</c:if>
37+
<c:if test="${!boo}">
38+
${map.user.name}
39+
</c:if>
40+
</td>
41+
<td>${map.creationTime} </td>
42+
<td>${map.lastAccessTime}</td>
43+
<td>${map.ip } </td>
44+
45+
<td>
46+
<c:if test="${!boo&&user.admin}">
47+
<a href="<c:url value='/servlet/KickOutServlet?id=${map.id}'/> " >踢出${map.user.name}</a>
48+
</c:if>
49+
</td>
50+
</tr>
51+
</c:forEach>
52+
</table>
53+
<br/>网站访问量:${count}
54+
</body>
55+
</html>

myOnlinesWeb2/myOnlinesWeb2.zip

27.4 KB
Binary file not shown.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cn.hncu.domain;
2+
3+
public class User {
4+
private String name;
5+
private String pwd;
6+
private boolean admin;
7+
8+
public User() {
9+
}
10+
11+
public String getName() {
12+
return name;
13+
}
14+
15+
public void setName(String name) {
16+
this.name = name;
17+
}
18+
19+
public String getPwd() {
20+
return pwd;
21+
}
22+
23+
public void setPwd(String pwd) {
24+
this.pwd = pwd;
25+
}
26+
27+
public boolean isAdmin() {
28+
return admin;
29+
}
30+
31+
public void setAdmin(boolean admin) {
32+
this.admin = admin;
33+
}
34+
35+
36+
}

0 commit comments

Comments
 (0)