求助,跟书本一模一样但是就是错了。
j2ee吧
全部回复
仅看楼主
level 6
p121a.jsp
<%!
public String Bytes(String str)
{
try
{
String strOld=str;
byte[] strNew=strOld.getBytes("ISO-8859-1");
String bytes=new String(strNew);
return bytes;
}
catch(Exception e){}
return null;
}
%>
p135.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=GB2312"%>
<html>
<head>
<title>商品搜索</title>
<style type="text/css">
<!--
.style1{font-size:12px}
.style2{color:#ff0000}
-->
</style>
</head>
<body>
<form name="form1" onsubmit="return check()" method="post" action="p137.jsp">
<table width="80%" border="0" align="center" bgcolor="#0099ff">
<tr bgcolor="#ffffff">
<th height="39" scope="row">
<div align="left">
<span style="font-weight:400"><font size="2">查询项目:</font>
</span>
</div>
</th>
<td>
<select name="item" size=1>
<option value="">请选择</option>
<option value="p_type">p_type</option>
<option value="p_id">p_id</option>
<option value="p_name">p_name</option>
</select>
</td>
<td><font size="2">查询内容:</font></td>
<td><input type="text" name="content"></td>
<td><input type="submit" name="submit" value="查询"/></td>
</tr>
</table>
</form>
</body>
<script type="text/javascript">
function check()
{
if(form1.content.value=="")
{
alert("请输入查询内容!");
form1.content.focus();
return false;
}
}
</script>
</html>
p137.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=GB2312"%>
<%@ page import="java.sql.*" %>
<html>
<head> <title>商品搜索结果</title></head>
<style type="text/css">
<!--
.style1{font-size:12px}
.style2P{color:#ff0000}
-->
</style>
<body>
<jsp:include page="p135.jsp"/>
<%@ include file="p121a.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=Shop System";
conn=DriverManager.getConnection(strConn,"sa","123456");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String strItem=request.getParameter("item");
String strContent=Bytes(request.getParameter("content"));
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 priduct 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" color="#0000ff">商品编号</font></td>
<td><font size="2" color="#0000ff">商品名称</font></td>
<td><font size="2" color="#0000ff">商品类别</font></td>
<td><font size="2" color="#0000ff">商品价格</font></td>
<td><font size="2" color="#0000ff">商品数量</font></td>
<td><font size="2" color="#0000ff">上架日期</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_name") %></font></td>
<td><font size="2"><%=rsAll.getString("p_type") %></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><a href="#"><font size="2">详情</font></a></td>>
<td><a href="#"><font size="2">购买</font></a></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="p137.jsp?page=1">第一页</a><a href="p137.jsp?page=<%=currentPage-1 %>">上一页</a>
<%
}
if(currentPage<maxPage)
{
%>
<a href="p137.jsp?page=<%=currentPage+1 %>">下一页</a> <a href="p137.jsp>page=<%=maxPage %>">最后一页 </a>
<%
}
rsAll.close();
stmt.close();
conn.close();
%>
</font></p>
</body>
</html>
估计是p137.jsp错了,但是不知道错在哪里,求大神指点迷津。
2014年11月13日 01点11分 1
level 5
报的是66行,rsAll的操作报错
可能是数据库查询出现了问题
--- rsAll=stmt.executeQuery(strSql);
看报错下面具体的是个空指针的错,
建议检查下数据库状态和链接配置,
另外
tomcat的work目录下可以找到编译完成的p137_jsp.java
可以看一下具体的146行是什么
2014年11月16日 07点11分 2
已解决
2014年11月19日 13点11分
1