@Huaxu's
ok 谢谢了
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/bookstore" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="123456" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/bookstore?autoReconnect=true"/>
</Context> //这是context文件
//以下是index.jsp 转换的时候从conn=ds.connection()抛出异常 说
//can not load"com.mysql.jdbc.Driver"
<%@ page contentType="text/html;charset=gb2312" import="java.sql.*,javax.sql.*,javax.naming.*" %>
<html>
<head>
<title>留言板</title>
</head>
<body>
<a href="say.html">我要留言</a>
<%
Context ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/bookstore");
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from guestbook order by gst_time desc");
rs.last();
int rowCount=rs.getRow();
if(rowCount==0){
out.println("当前没有任何留言");
return;
}
String strCurPage=request.getParameter("page");
int curPage;
if(strCurPage==null){
curPage=1;
}
else
curPage=Integer.parseInt(strCurPage);
int countPerPage=5;
int pageCount=(rowCount+countPerPage-1)/countPerPage;
rs.absolute((curPage-1)*countPerPage+1);
if(curPage==1){
%>
第一页
上一页
<%
}
else{
%>
<a href="index.jsp?page=<%=1%>">第一页</a>
<a href="index.jsp?page=<%=curPage-1%>">上一页</a>
<%
}
if(curPage==pageCount){
%>
下一页
最后页
<%
}
else{
%>
<a href="index.jsp?page=<%=curPage+1%>">下一页</a>
<a href="index.jsp?page=<%=pageCount%>">最后页</a>
<%
}
int i=0;
while(i<countPerPage&&!rs.isAfterLast()){
out.println("<hr color='blue' size='2'><br>");
out.println("用户名:"+rs.getString("gst_user"));
out.println(" ");
Timestamp ts=rs.getTimestamp("gst_time");
long lms=ts.getTime();
Date date=new Date(lms);
Time time=new Time(lms);
out.println("留言时间:"+date+" "+time);
out.println(" ");
out.println("用户IP: "+rs.getString("gst_ip")+"<br>");
out.println("主题:"+rs.getString("gst_title")+"<br>");
out.println("内容:"+rs.getString("gst_content"));
i++;
rs.next();
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
回复 更多评论