如果用语句更新数据库中文章点击次数,则页面显示不完全。把更新数据库的语句注释掉,一切正常。
下面是代码
<%@ include file="top.jsp" %>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:Jsp"; // Jsp 为你的用户数据源名称;
String user="sa";
String password=""; // 用户名和密码在此都设为空;
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
%>
<%
String id=request.getParameter("id");
%>
<table width="768" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td height="20" colspan="2" style="border: 1 solid #C0C0C0">
<%
String sql="select * from cat";
ResultSet cat=stmt.executeQuery(sql);
while(cat.next()) {%>
<a href="show.jsp?cat_id=<%= cat.getString(1) %>"><%=cat.getString(2)%></a>
|
<%
}
cat.close();
%>
</td>
</tr>
<tr>
<td width="210" height="300" valign="top" style="border-left: 1 solid #C0C0C0">
<table width="98%" border="0">
<tr>
<td width="60%"><span class="diyColor0">Top10[All]</span></td>
<td width="38%"> </td>
</tr>
<%
String top10="select top 10 * from article order by hit desc";
ResultSet top=stmt.executeQuery(top10);
while(top.next()){%>
<tr>
<td colspan="2"><a href="Article.jsp?id=<%= top.getString(1) %>"><%=top.getString(3) %></a></td>
</tr>
<%
}
top.close();
%>
</table></td>
<td width="558" valign="top" style="border-right: 1 solid #C0C0C0;
border-left: 1 solid #C0C0C0">
<% String artsql="select * from article where id="+"'"+id+"'";
ResultSet rs=stmt.executeQuery(artsql); %>
<table width="100%" cellpadding="0" cellspacing="0" class="">
<%
String hit=new String("");
while(rs.next()){%>
<tr align="center">
<td height="20" valign="middle">
<font color="#FF0000"><%= rs.getString(3) %></font>
</td>
</tr>
<%
String content=rs.getString(4);
String posttime=rs.getString(5);
String isgood=rs.getString;
hit=rs.getString(7);
%>
<tr align="right">
<td height="20" valign="middle"> Posttime:[<%=posttime%>] Hits:[<%=hit%>] </td>
</tr>
<tr>
<td valign="middle"> <%=content%></td>
</tr>
<%
}
rs.close();
%>
</table>
</td>
</tr>
<tr style=" border-bottom:1 solid #C0C0C0">
<td height="38" colspan="3" background="images/bar_bg2.gif"
bgcolor="#c0c0c0" style="border-left: 1 solid #C0C0C0;
border-right: 1 solid #C0C0C0; border-top: 1 solid #C0C0C0">
</td>
</tr>
</table>
</body>
</html>
<%
int ihit = new Integer(hit).intValue()+1;
String upsql="update article set hit='"+ihit+"' where id='"+id+"'";
ResultSet up=stmt.executeQuery(upsql); //
//就是这一行。。可以用,但是表格下部显示不出来!
stmt.close();
conn.close();
%>
正常的图片
有错的图片
完整的文档
MyProject.rar (45.92k)