在聊天室里聊天内容不显示,为什么呢??

//dataValue.jsp<html><%@includefile="./checklogin.jsp"%><%@pagelanguage="java"import=... //dataValue.jsp
<html>
<%@ include file="./checklogin.jsp" %>
<%@ page language="java" import="java.sql.*" pageEncoding="GB2312"%>
<%@ page import="com.util.DBConn"%>
<head>
<script language="javascript">
//javascript函数,每融2000毫秒(2秒)刷新一次页面
function GetData()
{
var timeoutid = setTimeout("window.location.reload()",2000)
}
</script>
</head>
<body onload="GetData()">

<%
String msgString = "";
Connection conn=null;
PreparedStatement stmt =null;
ResultSet rs =null;
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=(String)session.getAttribute("user_id");
String chatroom=(String)session.getAttribute("chatroom");
conn=DBConn.getConn();
stmt = conn.prepareStatement(sql);
stmt.setString(1,chatroom);
rs = stmt.executeQuery();

//下面while循环里的程序就是实现控制聊天信息显示格式的功能
while(rs.next())
{
String msgFrom = rs.getString("msgFrom");//获取聊天信息发送者
String msgTo=rs.getString("msgTo");//获取聊天信息接收者
String action = rs.getString("chatAction");//获取聊天表情
String msgContent=rs.getString("msgContent");//获取聊天信息内容
msgString=msgString+"<div><font color=blue>"+msgFrom+"</font>对<font color=blue>"+msgTo+"</font></span>说:"+msgContent+"</div>";
%>
<script language="javascript">
//注意这里的javascript,在show.jsp中定义了一个id为loadContent的span
//这里就是在id为loadContent的地方显示msgString,也就是显示聊天信息
parent.loadContent.innerHTML="<%=msgString%>";
parent.location.hash="position";
</script>
</body>
</html>

//show.jsp
<html>
<%@ page language="java" pageEncoding="utf-8"%>
<head>
<script language="javascript" type="text/javascript">
function GetPosition()
{
window.location.hash="position";
}
function GetData()
{
url="dataValue.jsp";//调用页面

var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open("GET",url,false);
http.send();
var str = http.responseText;
loadContent.innerHTML=str;
setTimeout("GetData()",1000);
}

</script>
</head>
<body onload="GetData()" background="images\4.jpg">
<span id="loadContent">data is loading</span>
<a id="position"></a>
</body>
</html>
展开
 我来答
幼稚开心果
2011-05-05
知道答主
回答量:4
采纳率:0%
帮助的人:0
展开全部
//dataValue.jsp
<html>
<%@ include file="./checklogin.jsp" %>
<%@ page language="java" import="java.sql.*" pageEncoding="GB2312"%>
<%@ page import="com.util.DBConn"%>
<head>
<script language="javascript">
//javascript函数,每融2000毫秒(2秒)刷新一次页面
function GetData()
{
var timeoutid = setTimeout("window.location.reload()",2000)
}
</script>
</head>
<body onload="GetData()">

<%
String msgString = "";
Connection conn=null;
PreparedStatement stmt =null;
ResultSet rs =null;
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=(String)session.getAttribute("user_id");
String chatroom=(String)session.getAttribute("chatroom");
conn=DBConn.getConn();
stmt = conn.prepareStatement(sql);
stmt.setString(1,chatroom);
rs = stmt.executeQuery();

//下面while循环里的程序就是实现控制聊天信息显示格式的功能
while(rs.next())
{
String msgFrom = rs.getString("msgFrom");//获取聊天信息发送者
String msgTo=rs.getString("msgTo");//获取聊天信息接收者
String action = rs.getString("chatAction");//获取聊天表情
String msgContent=rs.getString("msgContent");//获取聊天信息内容
msgString=msgString+"<div><font color=blue>"+msgFrom+"</font>对<font color=blue>"+msgTo+"</font></span>说:"+msgContent+"</div>";
%>
<script language="javascript">
//注意这里的javascript,在show.jsp中定义了一个id为loadContent的span
//这里就是在id为loadContent的地方显示msgString,也就是显示聊天信息
parent.loadContent.innerHTML="<%=msgString%>";
parent.location.hash="position";
</script>
</body>
</html>

//show.jsp
<html>
<%@ page language="java" pageEncoding="utf-8"%>
<head>
<script language="javascript" type="text/javascript">
function GetPosition()
{
window.location.hash="position";
}
function GetData()
{
url="dataValue.jsp";//调用页面

var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open("GET",url,false);
http.send();
var str = http.responseText;
loadContent.innerHTML=str;
setTimeout("GetData()",1000);
}

</script>
</head>
<body onload="GetData()" background="images\4.jpg">
<span id="loadContent">data is loading</span>
<a id="position"></a>
</body>
</html>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式