<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>测试商品搜索</title>
</head>
<body>
<%@include file="convert.jsp"%>
<%
Connection conn=null;
ResultSet rsAll=null;
Statement stmt=null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String strConn="jdbc:sqlserver://localhost:1433;DatabaseName=ShopSystem";
String strUser="sa";
String strPassword="sa";
conn=DriverManager.getConnection(strConn,strUser,strPassword);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String strItem=request.getParameter("item");
String strContent=Bytes(request.getParameter("co"));
String strSql="";
if(strItem==null||strItem=="")
{
strSql="select p_id,p_type,p_name,p_price,p_quantity,p_time from product";
}
else
{
strSql="select p_id,p_type,p_name,p_price,p_quantity,p_time from product where "+strItem.trim()+"LIKE'%"+strContent.trim()+"%'";
}
rsAll=stmt.executeQuery("strSql");
}
catch(Exception e){e.printStackTrace();}
%>
<table width=80% border=1 cellspacing=0 align=center>
<tr>
<td><font size=2>商品编号</font></td>
<td><font size=2>商品类别</font></td>
<td><font size=2>商品名称</font></td>
<td><font size=2>商品价格</font></td>
<td><font size=2>商品数量</font></td>
<td><font size=2>上架日期</font></td>
</tr>
<%
String str=(String)request.getParameter("page");
if(str==null)
{
str="0";
}
int pagesize=10;
rsAll.last();
int recordCount=rsAll.getRow();
int maxPage=0;
maxPage=(recordCount%pagesize==0)?(recordCount/pagesize):(recordCount/pagesize+1);
int currentPage=Integer.parseInt(str);
if(currentPage<1)
{
currentPage=1;
}
else
{
if(currentPage>maxPage){currentPage=maxPage;}
}
rsAll.absolute((currentPage-1)*pagesize+1);
for(int i=1;i<pagesize;i++)
{
%>
<tr>
<td><font size=2><%= rsAll.getString("p_id") %></font></td>
<td><font size=2><%= rsAll.getString("p_type") %></font></td>
<td><font size=2><%= rsAll.getString("p_name") %></font></td>
<td><font size=2><%= rsAll.getString("p_price") %></font></td>
<td><font size=2><%= rsAll.getString("p_quantity") %></font></td>
<td><font size=2><%= rsAll.getString("p_time") %></font></td>
<td><font size=2><a href="#">详情</a></font></td>
<td><font size=2><a href="#">购买</a></font></td>
</tr>
<%
try
{
if(!rsAll.next())
{
break;}
}
catch(Exception e){}
}
%>
</table>
<p align=center><font size=2>跳转到:<input type=text name=page size=3>当前页数:【<%= currentPage%>/<%=maxPage%>】 ;
<%
if(currentPage>1)
{
%>
<a href="search_result.jsp?page=1">第一页</a>
<a href="search_result.jsp?page=<%=currentPage-1 %>">上一页</a>
<%
}
if(currentPage<maxPage)
{
%>
<a href="search_result.jsp?page=<%=currentPage+1%>">下一页</a>
<a href="search_result.jsp?page=<%=maxPage %>"></a>
<%
}
rsAll.close();
stmt.close();
conn.close();
%>
</font></p>
</body>
</html>数据库在360网盘里
昵称:wps枫桥夜泊
密码:178743782
<%@ page import="java.sql.*" %>
<html>
<head>
<title>测试商品搜索</title>
</head>
<body>
<%@include file="convert.jsp"%>
<%
Connection conn=null;
ResultSet rsAll=null;
Statement stmt=null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String strConn="jdbc:sqlserver://localhost:1433;DatabaseName=ShopSystem";
String strUser="sa";
String strPassword="sa";
conn=DriverManager.getConnection(strConn,strUser,strPassword);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String strItem=request.getParameter("item");
String strContent=Bytes(request.getParameter("co"));
String strSql="";
if(strItem==null||strItem=="")
{
strSql="select p_id,p_type,p_name,p_price,p_quantity,p_time from product";
}
else
{
strSql="select p_id,p_type,p_name,p_price,p_quantity,p_time from product where "+strItem.trim()+"LIKE'%"+strContent.trim()+"%'";
}
rsAll=stmt.executeQuery("strSql");
}
catch(Exception e){e.printStackTrace();}
%>
<table width=80% border=1 cellspacing=0 align=center>
<tr>
<td><font size=2>商品编号</font></td>
<td><font size=2>商品类别</font></td>
<td><font size=2>商品名称</font></td>
<td><font size=2>商品价格</font></td>
<td><font size=2>商品数量</font></td>
<td><font size=2>上架日期</font></td>
</tr>
<%
String str=(String)request.getParameter("page");
if(str==null)
{
str="0";
}
int pagesize=10;
rsAll.last();
int recordCount=rsAll.getRow();
int maxPage=0;
maxPage=(recordCount%pagesize==0)?(recordCount/pagesize):(recordCount/pagesize+1);
int currentPage=Integer.parseInt(str);
if(currentPage<1)
{
currentPage=1;
}
else
{
if(currentPage>maxPage){currentPage=maxPage;}
}
rsAll.absolute((currentPage-1)*pagesize+1);
for(int i=1;i<pagesize;i++)
{
%>
<tr>
<td><font size=2><%= rsAll.getString("p_id") %></font></td>
<td><font size=2><%= rsAll.getString("p_type") %></font></td>
<td><font size=2><%= rsAll.getString("p_name") %></font></td>
<td><font size=2><%= rsAll.getString("p_price") %></font></td>
<td><font size=2><%= rsAll.getString("p_quantity") %></font></td>
<td><font size=2><%= rsAll.getString("p_time") %></font></td>
<td><font size=2><a href="#">详情</a></font></td>
<td><font size=2><a href="#">购买</a></font></td>
</tr>
<%
try
{
if(!rsAll.next())
{
break;}
}
catch(Exception e){}
}
%>
</table>
<p align=center><font size=2>跳转到:<input type=text name=page size=3>当前页数:【<%= currentPage%>/<%=maxPage%>】 ;
<%
if(currentPage>1)
{
%>
<a href="search_result.jsp?page=1">第一页</a>
<a href="search_result.jsp?page=<%=currentPage-1 %>">上一页</a>
<%
}
if(currentPage<maxPage)
{
%>
<a href="search_result.jsp?page=<%=currentPage+1%>">下一页</a>
<a href="search_result.jsp?page=<%=maxPage %>"></a>
<%
}
rsAll.close();
stmt.close();
conn.close();
%>
</font></p>
</body>
</html>数据库在360网盘里
昵称:wps枫桥夜泊
密码:178743782
解决方案 »
- js判断输入必须是数字
- Ant 自定义Task,嵌套Task,而且在内部Task需要传值!
- 我这个SQL语句怎么有问题???oracle
- 把<textarea 控件里的文本录入到数据库,然后在取出显示在html上,怎么保持原格式
- jsp怎么调用servlet?
- Tomcat4.1中的jndi DataSource获得的Connection为什么只能自动commit?
- 请叫一个很菜的问题?
- 为什么要将apache和tomcat整合配置呢?apache有什么功能????难道只是速度吗???
- JS获取<table>中<tr>的数据
- Spring boot用了shiro如何控制templates目录下的权限?
- 求一个Eclipse集成SSH和tomcat的IDE
- 受限网站,网站cookie被IE默认的隐私设置阻挡!
数据库在这个网址里:
http://pan.baidu.com/share/link?shareid=145847&uk=2551188755
不对啊,错误提示如下
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: An exception occurred processing JSP page /shiyong/search_result.jsp at line 5249: str="0";
50: }
51: int pagesize=10;
52: rsAll.last();
53: int recordCount=rsAll.getRow();
54: int maxPage=0;
55: maxPage=(recordCount%pagesize==0)?(recordCount/pagesize):(recordCount/pagesize+1);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause java.lang.NullPointerException
org.apache.jsp.shiyong.search_005fresult_jsp._jspService(search_005fresult_jsp.java:128)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.29