跪求大神解决下!!!JSP之间参数传递以及在JSP中调用bean连接mySQL数据库进行查询时出错,这个主要是做的机票查询页面
<%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%>
<%@pageimport="javax.servlet.*"import="java.sql.*"%>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gbk"/>
<title>机票查询</title>
<scripttype="text/javascript"src="js/mootools.js"></script>
<scripttype="text/javascript"src="js/calendar.rc4.js"></script>
<scripttype="text/javascript">
//<![CDATA[
window.addEvent('domready',function(){
myCal1=newCalendar({date1:'d/m/Y'},{direction:1,tweak:{x:6,y:0}});
myCal2=newCalendar({date2:'d/m/Y'},{classes:['dashboard'],direction:1,tweak:{x:3,y:-3}});
myCal3=newCalendar({date3:'d/m/Y'},{classes:['i-heart-ny'],direction:1,tweak:{x:3,y:0}});
});
//]]>
</script>
<linkrel="stylesheet"type="text/css"href="css/iframe.css"/>
<linkrel="stylesheet"type="text/css"href="css/calendar.css"/>
<linkrel="stylesheet"type="text/css"href="css/dashboard.css"/>
<linkrel="stylesheet"type="text/css"href="css/i-heart-ny.css"/>
<linkrel="stylesheet"type="text/css"href="css.css"/>
</head>
<jsp:useBeanid="be"class="com.hncz.bean"scope="request"></jsp:useBean>
<body>
<%
Stringflight_no="",dep="",des="",
dep_time="",arr_time="",ps="";
floatprice=0;
intsum=0;
%>
<divid="wrap">
<divid="top">
<divclass="nothing"></div>
<divid="nav">
<ul>
<li><ahref="query.jsp">机票查询</a></li>
<li><ahref="book.jsp">机票预订</a></li>
<li><ahref="refund.jsp">退票</a></li>
<li><ahref="endorse.jsp">改签</a></li>
</ul>
</div>
</div>
<divid="main">
<divid="up">
<divid="upleft">
<formaction="querycheck.jsp"class="long">
<fieldset>
<label>出发地</label>
<inputid="input"type="text"name="dep"value=""/>
<label>目的地</label>
<inputid="input"type="text"name="des"value=""/>
<label>出发日期</label>
<inputid="date1"type="text"name="dep_date"value=""/>
</fieldset>
</form>
</div>
<divid="upright">
<inputid="button"type="submit"value="查询"/>
</div>
</div>
<divid="down">
<divid="container">
<tablewidth="820"border="1"id="table">
<tr>
<th>航次</th>
<th>出发站</th>
<th>到达站</th>
<th>出发时间</th>
<th>到达时间</th>
<th>历时</th>
<th>余票</th>
<th>票价</th>
<th>备注</th>
</tr>
<%Stringsql=(String)session.getAttribute("sql");
ResultSetrs=be.query(sql);
if(!rs.next())
{
%>
<script>
alert("没有符合条件的机票,请你重新查询");
window.location.href="query.jsp"
</script>
<%
}
while(rs.next()){
flight_no=rs.getString("flight_no");
dep=rs.getString("dep");
des=rs.getString("des");
dep_time=rs.getString("dep_time");
arr_time=rs.getString("arr_time");
sum=rs.getInt("sum");
price=rs.getFloat("price");
ps=rs.getString("ps");
%>
<tr>
<td><%=flight_no%></td>
<td><%=dep%></td>
<td><%=des%></td>
<td><%=dep_time%></td>
<td><%=arr_time%></td>
<td><%=Integer.parseInt(arr_time)-Integer.parseInt(dep_time)%></td>
<td><%=sum%></td>
<td><%=price%></td>
<td><%=ps%></td>
</tr>
<%}%>
</table>
</div>
</div>
</div>
<divid="footer">Copyright©2008-2013滕州论坛AllrightsAllrightsreserved.来源:<ahref="http://www.mycodes.net/"target="_blank">源码之家</a></div>
</div>
</body>
</html>
这是我的查询页面,输入的参数通过表单传递到下一个jsp页面
================================================================================================
<%@pagelanguage="java"import="java.sql.*"pageEncoding="GBK"%>
<%@pageimport="javax.servlet.*"%>
<html>
<head>
<title>验证注册表单</title>
</head>
<jsp:useBeanid="be"class="com.hncz.bean"scope="request"/>
<body>
<%
Stringdep=newString(request.getParameter("dep").getBytes("ISO-8859-1"),"utf-8");
Stringdes=newString(request.getParameter("des").getBytes("ISO-8859-1"),"utf-8");
Stringdep_date=request.getParameter("dep_date");
ResultSetrs=null;
if(dep.length()==0||des.length()==0||dep_date.length()==0)
{%>
<script>
alert("查询条件不能为空");
window.location.href="query.jsp"
</script>
<%}
else{
Stringsql="selectflight_no,dep,des,dep_time,arr_time"+
",arr_time-dep_time,sum,price,psfromflightwheredep="
+dep+"anddes="+des+"anddep_date="+dep_date;
//把获得的数据存放在session中
session.setAttribute("sql",sql);
}%>
</body>
</html>
===============================================================================================
每次出错的原因都是:
typeExceptionreport
messageAnexceptionoccurredprocessingJSPpage/query.jspatline85
descriptionTheserverencounteredaninternalerrorthatpreventeditfromfulfillingthisrequest.
exception
org.apache.jasper.JasperException:AnexceptionoccurredprocessingJSPpage/query.jspatline85
82:
83:<%Stringsql=(String)session.getAttribute("sql");
84:ResultSetrs=be.query(sql);
85:if(!rs.next())
86:{
87:%>
88:<script>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
rootcause
java.lang.NullPointerException
org.apache.jsp.query_jsp._jspService(query_jsp.java:157)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/7.0.55logs.
新人在此,有哪里不详细的地方
求包含求解决!!!!
------解决思路----------------------你直接在if前alert(rs.next())一下,,,看看弹出是什么结果。排查一下是不是be.query(sql);有问题。
------解决思路----------------------若楼主采用的是java后台。。。可以使用Java中DataFormat