12
返回列表 发新帖
楼主: bbjjez

JSP问题,求教!急!

[复制链接]
论坛徽章:
0
11#
 楼主| 发表于 2006-5-8 12:58 | 只看该作者
照你看!  你看我上面的代码那里出错了????  我想来想去也想不通!  试也试过了!  不助!!!  求教!谢谢

使用道具 举报

回复
论坛徽章:
0
12#
 楼主| 发表于 2006-5-8 13:09 | 只看该作者
我现在出现的问题就是在"第四部分代码"(一楼有标明)中的:<a href="list.jsp?sortid=<%/*=RS.getString("class"*/%>&rootid=<%/*=RS.getString("parentclass"*/%>">[<%=RS.getString("class"%>]</a><A href='show.jsp?id=<%/*=RS.getString("id"*/%>' title="<%/*=RS.getString("title"*/%>" class="TableLink"><u>
<%/*title=RS.getString("title";

if (title.length()>12){
title=title.substring(0,11);
out.println(title+"...";}else{
out.println(title);}*/%>  处出错。如果我除去以上的标识:/* */  后,JSP文档就会编译不了!!! 查来查去也查不出原因阿!郁闷阿!!!!

使用道具 举报

回复
论坛徽章:
0
13#
发表于 2006-5-8 15:43 | 只看该作者
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 6.
问题出在你重复调用了rs.getString("title",读取了title列,而ResultSet是不能重复读取的
解决方法:定义一个临时变量来存放String

使用道具 举报

回复
论坛徽章:
0
14#
 楼主| 发表于 2006-5-8 16:47 | 只看该作者
第二、第三代码段好像也和第四代码段一样,也重用了!为什么它可以运行??? 请问! 谢谢!

使用道具 举报

回复
论坛徽章:
0
15#
 楼主| 发表于 2006-5-8 16:50 | 只看该作者
每个代码段用完了RS之后,都有RS.close();关闭它阿!这样不行吗?   谢谢

使用道具 举报

回复
论坛徽章:
0
16#
 楼主| 发表于 2006-5-8 17:05 | 只看该作者
我在11楼中说道的代码中:    [<%=RS.getString("class"%>]   它没有加上:/*  */ 此注释,因为它可以取出数据!!!!  而且,我将  rs.getString("title"   取代了 RS.getSting("class"   也可以翻译成功,浏览器上可以取出相应数据阿!!!!  请问为什么呢????  谢谢

使用道具 举报

回复
论坛徽章:
0
17#
发表于 2006-5-8 18:32 | 只看该作者
看一下取出的结果集第6列是什么字段,问题确实是出在rs.getString()上,编译器是不会骗人的。

使用道具 举报

回复
论坛徽章:
0
18#
 楼主| 发表于 2006-5-8 22:56 | 只看该作者
哦,好的!!! 我试下啦,你说我应该怎样修改好阿???  谢谢

使用道具 举报

回复
论坛徽章:
0
19#
 楼主| 发表于 2006-5-9 10:17 | 只看该作者
几种方法都试过了!还是不行阿!!!!   sortid=<%=RS.getString("class"%> 处取不出数据(错误提示),可是在别处就能!  我尝试只用sortid=<%=RS.getString("class"%>   取class的数据赋给sortid 也不行阿!! 应该不存在RS重用问题!!!   rootid=<%=RS.getString("parentclass"%>就可以取出!!!!为什么呢??  我该怎么办阿?????    另外,><A href='show.jsp?id=<%=RS.getString("id"%>' title="<%=RS.getString("title"%>" class="TableLink"><u>
<%title=RS.getString("title";

if (title.length()>12){
title=title.substring(0,11);
out.println(title+"...";}else{
out.println(title);}%>  也出现同样问题阿!!!  救命阿!!!    求教!!  谢谢

使用道具 举报

回复
论坛徽章:
0
20#
 楼主| 发表于 2006-5-9 10:18 | 只看该作者
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<jsp:useBean id="sqlbean" scope="page" class="news.sql_data"/>
<HTML><HEAD><TITLE>企业内部管理信息平台</TITLE>

<link rel="stylesheet" href="newstyle.css" type="text/css">

<META http-equiv=Content-Type content="text/html; charset=gb2312">
</HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<CENTER><jsp:include page="header.jsp"/>
<TABLE cellSpacing=0 cellPadding=0 width=780>
<TBODY>
<TR>
<TD width="159" vAlign=top><TABLE cellSpacing=0 cellPadding=0 width="97%" border=0>
<TBODY>
<%String title; //第一部分JSP脚本
SimpleDateFormat sdf =new SimpleDateFormat( "MM-dd";
String sql = "Select count(*) as newsall FROM news";
ResultSet RS = sqlbean.executeQuery(sql);
RS.first();
String newsall=RS.getString("newsall";
RS.close();
//得到今天的日期
java.util.Date now = new java.util.Date();
DateFormat df = DateFormat.getDateInstance();
String s = df.format(now);
//完成
sql = "Select count(*) as todayall FROM news where datediff(hour,d,getdate())<24";
RS = sqlbean.executeQuery(sql);
RS.first();
String todayall=RS.getString("todayall";
RS.close();
sql = "Select sum(hit) as allhit FROM news";
RS = sqlbean.executeQuery(sql);
RS.first();//只取第一条记录
String allhit=RS.getString("allhit";
RS.close();%>
<TR>
<TD vAlign=top><br><br>
<TABLE width="99%" border=0 align=center cellPadding=2 cellSpacing=0 class="table3">
<TR>
<TD><img src="images/tongji.gif" width="140" height="41"></TD>
</TR>
<TR>
<TD><img src="images/jt.gif" width="17" height="19">共有信息:<font color="#000000"><strong><%=newsall%></strong></font>条 </TD>
</TR>
<TR>
<TD><img src="images/jt.gif" width="17" height="19">今日更新:<font color="#000000"><strong><%=todayall%></strong></font>条</TD>
</TR>
<TR>
<TD><img src="images/jt.gif" width="17" height="19">总共浏览:<font color="#000000"><strong><%=allhit%></strong>次</font></TD>
</TR>
</TABLE>
</TD></TR>
</TBODY></TABLE></td>
<TD width="619" vAlign=top><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><br><br><img src="images/ad.jpg" width="610" height="44"></td>
</tr>
</table></TD>
</TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=780>
<TBODY>
<TR>
<TD vAlign=top width=168>
<TABLE style="BORDER-COLLAPSE: collapse" height=15
cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align="center" class="unnamed1" >-=热点关注=-</TD>
<TD>
<DIV align=right></DIV></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD vAlign=center><TABLE style="BORDER-COLLAPSE: collapse"
cellSpacing=0 cellPadding=0 width=154
border=0>
<TBODY>
<TR>
<TD width=10 height=36></TD>
<TD vAlign=top width=134>
<% sql = "Select top 10 id,title,hit FROM news order by hit desc"; //第二部分JSP脚本
RS = sqlbean.executeQuery(sql);
while (RS.next()){%>
<img src=images/ico1.gif><A href='show.jsp?id=<%=RS.getString("id"%>' title="<%=RS.getString("title"%>" class="TableLink"><%title=RS.getString("title";
if (title.length()>9){
title=title.substring(0,8);
out.println(title+"...";}else{
out.println(title);}
%></a><FONT color=#999999><%=RS.getString("hit"%></font><BR>
<%}
RS.close();%>
</TD>
<TD width=10></TD>
</TR></TBODY></TABLE></TD>
</TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD vAlign=center><TABLE cellSpacing=0 cellPadding=0 width=154 border=0>
<TBODY>
<TR>
<TD></TD>
<TD align="center" vAlign=top class="unnamed1">-=最新加入=-</TD>
<TD></TD>
</TR>
<TR>
<TD width=10 height=36></TD>
<TD vAlign=top width=134>
<% sql = "Select top 10 id,title,hit FROM news order by id desc"; //第三部分JSP脚本
RS = sqlbean.executeQuery(sql);
while (RS.next()){%>
<img src=images/ico1.gif><A href="show.jsp?id=<%=RS.getString("id"%>" title="<%=RS.getString("title")%>" class="TableLink"><%
title=RS.getString("title");
if (title.length()>9){
title=title.substring(0,8);
out.println(title+"...");}else{
out.println(title);}
%></a> <FONT color=#999999><%=RS.getString("hit")%></font><BR>
<%}
RS.close();%></TD>
<TD width=10></TD>
</TR>
</TBODY>
</TABLE></TD>
</TR>
</TBODY>
</TABLE></TD>
<TD width="610" valign="top">
<TABLE style="BORDER-COLLAPSE: collapse" cellSpacing=0
cellPadding=0 width=610 border=0>
<TBODY><tr><td colspan="4"><TABLE style="BORDER-COLLAPSE: collapse" cellSpacing=0
cellPadding=0 width=610 border=0>
<TBODY>
<TR>
<TD width="309"><TABLE style="BORDER-COLLAPSE: collapse"
cellSpacing=0 cellPadding=3 width=95% border=0>
<TBODY>
<% ResultSet RS_root = sqlbean.executeQuery("select top 4 class from class where parentclass='0' order by id");
RS_root.first();
sql = "Select top 8 * FROM news where parentclass='"+RS_root.getString("class")+"' order by id desc";
RS_root.close();
RS = sqlbean.executeQuery(sql);//第四部分代码

while (RS.next()){%>
<tr>
<TD width=16><IMG height=12 src="images/sword_org.gif"
width=12 border=0></TD>
<td style="LINE-HEIGHT: 150%; font-size: 9pt;"> <a href="list.jsp?sortid=<%/*=RS.getString("class")*/%>&rootid=<%/*=RS.getString("parentclass")*/%>">[<%=RS.getString("class")%>]</a><A href='show.jsp?id=<%/*=RS.getString("id")*/%>' title="<%/*=RS.getString("title")*/%>" class="TableLink"><u>
<%/*title=RS.getString("title");

if (title.length()>12){
title=title.substring(0,11);
out.println(title+"...");}else{
out.println(title);}*/%>
</u></a><FONT color=#999999><%=sdf.format(RS.getDate("d"))%></FONT ></td>
</tr>
<%}
RS.close();%>
<TR>
<TD width=16 height=10></TD>
<TD width=237 height=10></TD>
</TR>
</TBODY>
</TABLE>  </TD>
<TD width="301" valign="top"><TABLE style="BORDER-COLLAPSE: collapse"
cellSpacing=0 cellPadding=3 width=95% border=0>
<TBODY>
<%/*RS_root.next();
sql = "Select top 8 * FROM news where parentclass='"+RS_root.getString("class")+"' order by id desc";
RS = sqlbean.executeQuery(sql);

while (RS.next()){*/%>
<tr>
<TD width=16><IMG height=12 src="images/sword_org.gif"
width=12 border=0></TD>
<td style="LINE-HEIGHT: 150%; font-size: 9pt;"> [<A href='list.jsp?sortid=<%/*=RS.getString("class")*/%>&rootid=<%/*=RS.getString("parentclass")*/%>'><%/*=RS.getString("class")*/%></a>]<A href='show.jsp?id=<%/*=RS.getString("id")*/%>' title="<%/*=RS.getString("title")*/%>" class="TableLink"><u>
<%/*title=RS.getString("title");

if (title.length()>12){
title=title.substring(0,11);
out.println(title+"...");}else{
out.println(title);}*/%>
</u></a><FONT color=#999999><%/*=sdf.format(RS.getDate("d"))*/%></FONT ></td>
</tr>
<%/*}
RS.close();*/%>
<TR>
<TD width=16 height=10></TD>
<TD width=237
height=10></TD>
</TR>
</TBODY>
</TABLE></TD>
</TR></TBODY></TABLE>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><img src="images/ad2.jpg" width="610" height="67"></td>
</tr>
<tr>
<td width="51%" valign="top"><TABLE style="BORDER-COLLAPSE: collapse"
cellSpacing=0 cellPadding=3 width=95% border=0>
<TBODY>
<%/*RS_root.next();
sql = "Select top 8 * FROM news where parentclass='"+RS_root.getString("class")+"' order by id desc";
RS = sqlbean.executeQuery(sql);

while (RS.next()){*/%>
<tr>
<TD width=16><IMG height=12 src="images/sword_org.gif"
width=12 border=0></TD>
<td style="LINE-HEIGHT: 150%; font-size: 9pt;"> [<A href='list.jsp?sortid=<%/*=RS.getString("class")*/%>&rootid=<%/*=RS.getString("parentclass")*/%>'><%/*=RS.getString("class")*/%></a>]<A href='show.jsp?id=<%/*=RS.getString("id")*/%>' title="<%/*=RS.getString("title")*/%>" class="TableLink"><u>
<%/*title=RS.getString("title");

if (title.length()>12){
title=title.substring(0,11);
out.println(title+"...");}else{
out.println(title);}*/%>
</u></a><FONT color=#999999><%/*=sdf.format(RS.getDate("d"))*/%></FONT ></td>
</tr>
<%/*}
RS.close();*/%>
<TR>
<TD width=16 height=10></TD>
<TD width=237
height=10></TD>
</TR>
</TBODY>
</TABLE></td>
<td width="49%" valign="top"><TABLE style="BORDER-COLLAPSE: collapse"
cellSpacing=0 cellPadding=3 width=95% border=0>
<TBODY>
<%/*
RS_root.next();
sql = "Select top 8 * FROM news where parentclass='"+RS_root.getString("class")+"' order by id desc";
RS = sqlbean.executeQuery(sql);
//java.util.Date xx=rs.getDate(1);
// java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
//String s = df.format(xx);
RS_root.close();
while (RS.next()){*/%>
<tr>
<TD width=16><IMG height=12 src="images/sword_org.gif"
width=12 border=0></TD>
<td style="LINE-HEIGHT: 150%; font-size: 9pt;"> [<A href='list.jsp?sortid=<%/*=RS.getString("class")*/%>&rootid=<%/*=RS.getString("parentclass")*/%>'><%/*=RS.getString("class")*/%></a>]<A href='show.jsp?id=<%/*=RS.getString("id")*/%>' title="<%/*=RS.getString("title")*/%>" class="TableLink"><u>
<%/*title=RS.getString("title");

if (title.length()>12){
title=title.substring(0,11);
out.println(title+"...");}else{
out.println(title);}*/%>
</u></a><FONT color=#999999><%/*=sdf.format(RS.getDate("d"))*/%></FONT ></td>
</tr>
<%/*}
RS.close();*/%>
<TR>
<TD width=16 height=10></TD>
<TD width=237
height=10></TD>
</TR>
</TBODY>
</TABLE></td>
</tr>
</table></td></tr>
</TBODY></TABLE></TD></TR></TBODY></TABLE>
<jsp:include page="bottom.jsp"/>

</CENTER>
</BODY></HTML>

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表