写了一段jsp代码,但是现在需要添加一个删除和添加的功能。根据三个文本框中输入的值进行删除和添加。 20
<h1align="center">用户信息列表</h1><divalign="center"><%intpageSize=3;intpageNow=1;introwCo...
<h1 align="center">用户信息列表</h1>
<div align="center">
<%
int pageSize=3;
int pageNow=1;
int rowCount=0;
int pageCount=0;//定义pageNow)
String s_pageNow=request.getParameter("pageNow");
if(s_pageNow!=null){
//接收到pageNow
pageNow=Integer.parseInt(s_pageNow);
}
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//加载数据库引擎,返回给定字符串名的类
Connection ct=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=webpage","b","123");
PreparedStatement ps=ct.prepareStatement("select count(*) from info");
ResultSet rs=ps.executeQuery()
if(rs.next()){
rowCount=rs.getInt(1);
}
//计算
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
//查询出需要显示的记录
ps=ct.prepareStatement("select top "+pageSize+" * from info where number not in(select top "+pageSize*(pageNow-1)+" number from info)");
rs=ps.executeQuery();
//显示
%>
<table border="1">
<tr><td>账号</td><td>密码</td><td>姓名</td></tr>
<%
while(rs.next()){
%>
<tr><td><%=rs.getString(1)%></td><td><%=rs.getString(2)%></td><td><%=rs.getString(3)%></td></tr>
<%
}
%>
</table>
<p>
<%
//上一页
if(pageNow!=1){
%>
<a href=try.jsp?pageNow=<%=pageNow-1%>>上一页</a>
<%
}
//显示超链接
for(int i=1;i<=pageCount;i++){
%>
<a href=try.jsp?pageNow=<%=i%>>[<%=i%>]</a>
<%
}
//下一页
if(pageNow!=pageCount){
%>
<a href=try.jsp?pageNow=<%=pageNow+1%>>下一页</a>
<%
}
%>
</p> 展开
<div align="center">
<%
int pageSize=3;
int pageNow=1;
int rowCount=0;
int pageCount=0;//定义pageNow)
String s_pageNow=request.getParameter("pageNow");
if(s_pageNow!=null){
//接收到pageNow
pageNow=Integer.parseInt(s_pageNow);
}
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//加载数据库引擎,返回给定字符串名的类
Connection ct=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=webpage","b","123");
PreparedStatement ps=ct.prepareStatement("select count(*) from info");
ResultSet rs=ps.executeQuery()
if(rs.next()){
rowCount=rs.getInt(1);
}
//计算
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
//查询出需要显示的记录
ps=ct.prepareStatement("select top "+pageSize+" * from info where number not in(select top "+pageSize*(pageNow-1)+" number from info)");
rs=ps.executeQuery();
//显示
%>
<table border="1">
<tr><td>账号</td><td>密码</td><td>姓名</td></tr>
<%
while(rs.next()){
%>
<tr><td><%=rs.getString(1)%></td><td><%=rs.getString(2)%></td><td><%=rs.getString(3)%></td></tr>
<%
}
%>
</table>
<p>
<%
//上一页
if(pageNow!=1){
%>
<a href=try.jsp?pageNow=<%=pageNow-1%>>上一页</a>
<%
}
//显示超链接
for(int i=1;i<=pageCount;i++){
%>
<a href=try.jsp?pageNow=<%=i%>>[<%=i%>]</a>
<%
}
//下一页
if(pageNow!=pageCount){
%>
<a href=try.jsp?pageNow=<%=pageNow+1%>>下一页</a>
<%
}
%>
</p> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询