?? datavalue.jsp.bak
字號(hào):
<html>
<%@include file="chkSession.jsp"%>
<%@ page language="java" import="java.sql.*" pageEncoding="GB2312"%>
<head>
<script language="javascript">
//javascript函數(shù),每融2000毫秒(2秒)刷新一次頁(yè)面
function GetData()
{
var timeoutid = setTimeout("window.location.reload()",2000)
}
</script>
</head>
<body onload="GetData()">
<jsp:useBean id="conn" class="net.chat.BaseConn" scope="page"/>
<%
//在這里我們定義了一個(gè)msgString,它保存頁(yè)面顯示的所有聊天信息,最后在show.jsp
//中顯示這個(gè)字符串
String msgString = "";
try
{
//從聊天信息數(shù)據(jù)庫(kù)中選取出最近的15條聊天信息
//這里要注意查詢語句的寫法
//select top 30 ID from msgInfo where chatRoom=? order by chatTime DESC這句查詢實(shí)際
//上已經(jīng)查詢出最新的30條信息
//但是這樣查詢出來的信息是按時(shí)間倒順排序的,最新的信息在最上面,而顯示的時(shí)候要
//把最新信息顯示在聊天室下面,所以要再做次查詢排序
String sql = "select * from msgInfo where ID in(select top 15 ID from msgInfo where chatRoom=? Order by chatTime DESC) order by chatTime";
String userName=session.getAttribute("_USER").toString();
PreparedStatement ps = conn.preparedStatement(sql);
ps.setString(1,session.getAttribute("_CHAT_ROOM").toString());
ResultSet rs = conn.executeQuery();
//下面while循環(huán)里的程序就是實(shí)現(xiàn)控制聊天信息顯示格式的功能
while(rs.next())
{
String msgFrom = rs.getString("msgFrom");//獲取聊天信息發(fā)送者
String msgTo=rs.getString("msgTo");//獲取聊天信息接收者
String action = rs.getString("chatAction");//獲取聊天表情
String msgContent=rs.getString("msgContent");//獲取聊天信息內(nèi)容
int secret = rs.getInt("secret");//獲取是否悄悄話
//判斷是否系統(tǒng)公告
if(msgFrom.equals("system notice"))
msgString=msgString+"<div>system notice:"+msgContent+"</div>";
//判斷是否悄悄話
else if(secret==0)
{
//判斷是否使用聊天表情
if(action==null||action.equals("no"))
msgString=msgString+"<div><font color=blue>"+msgFrom+"</font>對(duì)<font color=blue>"+msgTo+"</font></span>說:"+msgContent+"</div>";
else
msgString=msgString+"<div><font color=blue>"
+msgFrom+"</font>"+action.replaceAll("B","<font color=blue>"
+msgTo+"</font>")+msgContent+"</div>";
}
//如果是悄悄話只在發(fā)送者和接收者的頁(yè)面中顯示
else if(msgFrom.equals(userName)||msgTo.equals(userName))
{
if(action==null||action.equals("no"))
msgString=msgString+"<div><font color=red>[悄悄話]</font><font color=blue>"
+msgFrom+"</font>對(duì)<font color=blue>"+msgTo+"</font></span>說:"
+msgContent+"</div>";
else
msgString=msgString+"<div><font color=red>[悄悄話]</font><font color=blue>"
+msgFrom+"</font>"+action.replaceAll("B","<font color=blue>"
+msgTo+"</font>")+msgContent+"</div>";
}
}
}catch(Exception ex)
{
ex.printStackTrace();
out.println("系統(tǒng)維護(hù)");
}finally
{
conn.closeDB();
}
%>
<script language="javascript">
//注意這里的javascript,在show.jsp中定義了一個(gè)id為loadContent的span
//這里就是在id為loadContent的地方顯示msgString,也就是顯示聊天信息
parent.loadContent.innerHTML="<%=msgString%>";
parent.location.hash="position";
</script>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -