仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
楼主: 不帅
打印 上一主题 下一主题

[学习教程] JAVA教程之JSP在耳目数程序分析

[复制链接]
不帅 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:34:29 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
再说说缺点:首先java功能强大的背后是其复杂性,就拿web来说,当今流行的框架有很多,什么struts,spring,jQuery等等,而这无疑增加了java的复杂性。js|程序|在线|在耳目数/**这是办理user信息的类
文件名为onLineUser.java
*/
importjavax.servlet.http.*;
importjavax.servlet.*;
importjava.util.*;
publicclassonLineUserimplementsHttpSessionBindingListener{
publiconLineUser(){
}
privateVectorusers=newVector();
publicintgetCount(){
users.trimToSize();
returnusers.capacity();
}
publicbooleanexistUser(StringuserName){
users.trimToSize();
booleanexistUser=false;
for(inti=0;i<users.capacity();i++)
{
if(userName.equals((String)users.get(i)))
{
existUser=true;
break;
}
}
returnexistUser;
}
publicbooleandeleteUser(StringuserName){
users.trimToSize();
if(existUser(userName)){
intcurrUserIndex=-1;
for(inti=0;i<users.capacity();i++){
if(userName.equals((String)users.get(i))){
currUserIndex=i;
break;
}
}
if(currUserIndex!=-1){
users.remove(currUserIndex);
users.trimToSize();
returntrue;
}
}
returnfalse;
}
publicVectorgetOnLineUser()
{
returnusers;
}
publicvoidvalueBound(HttpSessionBindingEvente){
users.trimToSize();
if(!existUser(e.getName())){
users.add(e.getName());
System.out.print(e.getName()+"        登进到体系        "+(newDate()));
System.out.println("在线用户数为:"+getCount());
}else
System.out.println(e.getName()+"已存在");
}
publicvoidvalueUnbound(HttpSessionBindingEvente){
users.trimToSize();
StringuserName=e.getName();
deleteUser(userName);
System.out.print(userName+"        加入体系        "+(newDate()));
System.out.println("在线用户数为:"+getCount());
}
}
///////////////////////////////////////////////////////////
<%
/**这是显现在线用户的jsp文件
文件名为onLineUser.jsp
*/
%>
<%@pagecontentType="text/html;charset=gb2312"%>
<%@pageimport="onLineUser,java.util.*"%>
<jsp:useBeanid="onlineuser"class="onLineUser"scope="application"/>
<html>
<head>
<title>弄定JSP在耳目数</title>
</head>
<body>
<center>
<p><h1>上岸乐成,接待您会见Java家!</h1></p>
</center>
<%session=request.getSession(false);%>
<%
Stringusername=request.getParameter("username");
if(onlineuser.existUser(username)){
out.println("用户<fontcolor=red>"+username+"</font>已上岸!");
}else{
session.setMaxInactiveInterval(50);file://Sesion无效时长,以秒为单元
session.setAttribute(username,onlineuser);
out.println("接待新用户:<fontcolor=red>"+username+"</font>上岸到体系!");
}
out.println("<br>以后在线用户人数:<fontcolor=red>"+onlineuser.getCount()+"</font><br>");
Vectorvt=onlineuser.getOnLineUser();
Enumeratione=vt.elements();
out.println("在线用户列表");
out.println("<tableborder=1>");
out.println("<tr><td>用户名</td></tr>");
while(e.hasMoreElements()){
out.println("<tr><td>");
out.println((String)e.nextElement()+"<br>");
out.println("</td></tr>");
}
out.println("</table>");
%>
<center>
<p>yuking制造</p>
<p></p>
<%
out.println("<p><ahref=logout.jsp?username="+username+">加入体系</a></p>");
%>
</center>
</body>
</html>
///////////////////////////////////////////////////////////////////
<%
/**这是用户加入的jsp文件
文件名为logout.jsp
*/
%>
<%@pagecontentType="text/html;charset=gb2312"%>
<%@pageimport="onLineUser,java.util.*"%>
<jsp:useBeanid="onlineuser"class="onLineUser"scope="application"/>
<html>
<head>
<title>弄定JSP在耳目数</title>
</head>
<body>
<center>
<p><h1>上岸乐成,接待您会见Java家!</h1></p>
</center>
<%
Stringusername=request.getParameter("username");
if(onlineuser.deleteUser(username))
out.println(username+"已加入体系!");
else
out.println(username+"没有上岸到体系!");
%>
<center>
<p>yuking制造</p>
<p></p>
<p><ahref="logout.jsp">加入体系</a></p>
</center>
</body>
</html>

Java到底会发战成什么样,让我们拭目以待吧,我始终坚信着java会更好。以上都是俺个人看法,欢迎大家一起交流.
不帅 该用户已被删除
沙发
 楼主| 发表于 2015-6-9 06:03:10 | 显示全部楼层
Sun公司看见Oak在互联网上应用的前景,于是改造了Oak,于1995年5月以Java的名称正式发布。Java伴随着互联网的迅猛发展而发展,逐渐成为重要的网络编程语言。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-23 18:42

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表