你把你另一个jsp和bean贴出来,或许能帮你找到问题的原因
解决方案 »
- 请问xml文件能像jsp一样动态的显示数据吗?
- 关于页面条件搜索问题
- WinXP+SP2,sql server2000个人版+SP3,数据库连接问题
- JSP的错误页面跳转问题
- 救急!求实训平台的源代码(学校课程设计)
- javac 时,如何才能使用同一包下的其它类?包mypack, 类A.class, B.class, 因为B中用到A,编译B时说找不到A
- checkbox如何返回全部参数,包括已勾选,和未勾选的,返回已勾选的,我知道。
- 求助Java Servlet
- 哪有gservany(把应用程序作为2000/nt服务)的下载。马上给分
- struts2 if标签无论怎么样都进不去if
- 汉字问题!为什么用quest.getParameter得到的url传来的汉字参数为????怎么转汉字编码给参数呀?(急......!)
- 如何在servlet里调用JavaBean?
<%@page language="java"import ="java.sql.*,java.io.*,java.util.*"%>
<%@page contentType="text/HTML;charset=gb2312"%>
<jsp:useBean id="testBean" class="mypackage.gx"scope="session"/>
<html>
<head>
<title>员工信息表</title>
<meta http-equiv="Refresh" content="10;URL=../mis/showuser.jsp">
<%
StringBuffer userInfo=new StringBuffer();
StringBuffer pageInfo=new StringBuffer();
int pageSize=10;//定义一页显示的记录数
String paraPage=request.getParameter("page");//获得当前要请求的页
int currentPage=1;
try{currentPage=Integer.parseInt(paraPage);
}catch(Exception e)
{currentPage=1;
}
ResultSet rs=testBean.executeQuery("select * from users_inf");
rs.last();//指针置于底
int totalUser=rs.getRow();//获得总的记录数
int pageCount=(int)Math.ceil((float)totalUser/(float)pageSize);//计算出总页数:ceil()是个除法运算
int i=1;
rs.absolute((currentPage-1)*pageSize+1);//把指针放在要显示的第一个数据
//把结果放到变量userInfo中
while(i<=pageSize)
{
userInfo.append("<tr bgcolor=#ffffff>\n");
userInfo.append("<td align=center>"+((currentPage-1)*pageSize+i)+"</td>");
userInfo.append("<td align=center>"+"<a href='sendmessage.jsp?user_id="+rs.getString("user_id")+"'>"+rs.getString("user_name")+"</a>"+"</td>");
//userInfo.append("<td>"+rs.getString("user_password")+"</td>");
userInfo.append("<td>"+rs.getString("user_realname")+"</td>");
userInfo.append("</tr>");
if(!rs.next())//假如到底就推出循环
break;
i++;
}
//关闭数据库连接
rs.close();
/*把要显示的信息放到变量pageInfo中
把显示翻页的信息放到变量pageInfo中*/
pageInfo.append("第"+currentPage+"页共"+pageCount+"页共"+totalUser+"用户");//信息
if(currentPage>1)//在当前页大于一的页有向前翻页的连接,否则没有
pageInfo.append("<a href='showuser.jsp?page="+(currentPage-1)+"'><<上一页</a>");
else
pageInfo.append("<<上一页");
if(currentPage<pageCount)
pageInfo.append("<a href ='showuser.jsp?page="+(currentPage+1)+"'>>>下一页</a>");
else
pageInfo.append("下一页>>");
//显示结果
%>
</head>
<body>
<a href="general.jsp">离开通讯模块<a>
<table width="50%" border="0" align="center" cellpadding=5 cellspacing=1 bgcolor=#000000>
<tr align="center"bgcolor=#cccccc>
<td width="20%">编号</td>
<td width="40%">用户名称</td>
<td width="40%">真实姓名</td>
</tr>
<%=userInfo%>
</table>
<table width="80%" border="0" align="center">
<tr>
<td align=right><%=pageInfo%>
</td>
</tr>
</table>
<%
ResultSet rs2=testBean.executeQuery("select * from message_inf where user_id='"+session.getValue("id")+"' and isview='0'");
if(rs2.next())
{
out.print("你有新的留言");
%>
<a href="showmessage.jsp"><img src="mail.gif"></a>
<%
}
try
{ rs2.close();
testBean.closeConn();
testBean.closeStmt();
}catch(Exception e){System.err.println(e);}
%>
<center><h3>*****点击用户名称可以给该用户发消息******</h3></center>
<%@ include file="last.html"%>
</body>
</html>
数据库bean:
package mypackage;
import java.sql.*;
public class gx{
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";//数据库驱动
//数据库连接字符串
String sConnStr="jdbc:odbc:firm";
private Connection conn=null;
private Statement stmt=null;
private ResultSet rs=null;
//构造函数
public gx(){
try{
Class.forName(sDBDriver);//加载数据库驱动程序
}
catch (java.lang.ClassNotFoundException e){
System.err.println("firm()"+e.getMessage());
}//抛出例外
}
//定义executeQuery()函数
public ResultSet executeQuery(String sql){
rs=null;
try{
conn=DriverManager.getConnection(sConnStr,"sa","admin");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}
catch(SQLException e){
System.err.println("aq.executeQuery:"+e.getMessage());
}
return rs;
}
//定义executeUpdate()函数
public void executeUpdate(String sql){
stmt=null;
rs=null;
try{
conn=DriverManager.getConnection(sConnStr,"sa","admin");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
catch(SQLException e){
System.err.println("aq.executeUpdate:"+e.getMessage());
}
}
//定义close()为关闭程序
public void closeStmt(){
try{
stmt.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try{
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
谢谢你, Leemaasn(他这家伙不怀好意 :P)
我的bean在其他的程序里可以运行,但是到了这个jsp程序里就有问题了!
是这样的:
我的jsp程序:
<%@page language="java"import ="java.sql.*"%>
<%@page contentType="text/HTML;charset=gb2312"%>
<jsp:useBean id="testBean" class = "mypackage.gx"scope= "session"/>
<%
StringBuffer userInfo=new StringBuffer();
StringBuffer pageInfo=new StringBuffer();
int pageSize=10;//定义一页显示的记录数
String paraPage=request.getParameter("page");//获得当前要请求的页
int currentPage=1;
try{currentPage=Integer.parseInt(paraPage);
}catch(Exception e)
{currentPage=1;
}
ResultSet rs=testBean.executeQuery("select * from news_inf");
rs.last();//指针置于底
int totalUser=rs.getRow();//获得总的记录数
int pageCount=(int)Math.ceil((float)totalUser/(float)pageSize);//计算出总页数:ceil()是个除法运算
int i=1;
rs.absolute((currentPage-1)*pageSize+1);
while(i<=pageSize)
{
userInfo.append("<tr bgcolor=#ffffff>\n");
userInfo.append("<td align=center>"+((currentPage-1)*pageSize+i)+"</td>");
userInfo.append("<td>"+rs.getString("posttime")+"</td>");
userInfo.append("<td>"+rs.getString("news_title")+"</td>"); userInfo.append("<td>"+rs.getString("news_content")+"</td>");
userInfo.append("<td><a href='deletenews_ok.jsp?news_id="+rs.getString("news_id")+"'>删除</a></td>");
userInfo.append("</tr>");
if(!rs.next())//假如到底就推出循环
break;
i++;
}
//关闭数据库连接
try
{
rs.close();
testBean.closeConn();
testBean.closeStmt();
}catch(Exception e){System.err.println(e);}
/*把要显示的信息放到变量pageInfo中
把显示翻页的信息放到变量pageInfo中*/
pageInfo.append("第"+currentPage+"页共"+pageCount+"页共"+totalUser+"条新闻");//信息
if(currentPage>1)//在当前页大于一的页有向前翻页的连接,否则没有
pageInfo.append("<a href='shownews.jsp?page="+(currentPage-1)+"'><<上一页</a>");
else
pageInfo.append("<<上一页");
if(currentPage<pageCount)
pageInfo.append("<a href ='shownews.jsp?page="+(currentPage+1)+"'>>>下一页</a>");
else
pageInfo.append("下一页>>");
//显示结果
%><html>
<head>
<title>新闻</title>
</head>
<body>
<table width="80%" border="0" align="center" cellpadding=5 cellspacing=1 bgcolor=#000000>
<tr align="center"bgcolor=#cccccc>
<td width="7%">编号</td>
<td width="20%">发布时间</td>
<td width="23%">新闻名称</td>
<td width="43%">新闻内容</td><td width="7%">操作</td>
</tr>
<%=userInfo%>
</table>
<table width="80%" border="0" align="center">
<tr>
<td align=right><%=pageInfo%>
</td>
</tr>
</table>
<a href="addnews.html">添加新闻</a>
</body>
</html>
我在里面把:userInfo.append("<td><a href='deletenews_ok.jsp?news_id="+rs.getString("news_id")+"'>删除</a></td>");改成:userInfo.append("<td><a href='deletenews_ok.jsp?'>删除</a></td>");
结果就没有问题了!大家看是什么问题呢!我瞑思苦想还是想不通啊!!
是MS SQL SERVER的问题!他妈的换成了访问另外的一个数据库(professional版本)的结果就没有问题了!现在我把我的MS SQL SERVER删了,结果再装个人版,提示说不能装!我吐血!