库可以联上,但取不到数据,不知为什么,请高手帮帮忙
<%@page import="javax.servlet.*"%>
<%@page import="javax.servlet.http.*"%>
<html>
<head>
<link href="/jsp-examples/C/chxnet.css" rel="stylesheet" type="text/css">
<title>提交页面</title>
</head>
<body>
<jsp:useBean id="jdbc" scope="application" class="cn.ac.ict.jdbc"/>
<%String ue=request.getParameter("username");
String pd=request.getParameter("password");
String sql="select * from [USERTEST] where UNAME ='"+ue+"' and UPASS ='"+pd+"'";
ResultSet rt;
rt=jdbc.query(sql);
while(rt.next())
{session.setAttribute("username",ue);%>
<iframe><table width="201" height="200" cellspacing="0" cellpadding="0" bgcolor="#3E85DB">
<tr height="54" valign="middle"><td colspan=2 ><img src="/examples/jsp/images/logtu1.gif"></td></tr>
<tr><td><lable>欢迎您:</lable></td><td><%out.print((String)session.getAttribute("username"));}%></td><tr>
<tr><td><input type="button" value="退出" onclick="1.jsp"></td><td></td></tr><iframe>
</body>
</html>
jsp页面错误提示如下:
org.apache.jasper.JasperException: Exception in JSP: /login.jsp:18
15: String sql="select * from [USERTEST] where UNAME ='"+ue+"' and UPASS ='"+pd+"'";
16: ResultSet rt;
17: rt=jdbc.query(sql);
18: while(rt.next())
19: {session.setAttribute("username",ue);%>
20: <iframe><table width="201" height="200" cellspacing="0" cellpadding="0" bgcolor="#3E85DB">
21: <tr height="54" valign="middle"><td colspan=2 ><img src="/examples/jsp/images/logtu1.gif"></td></tr>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
org.apache.jsp.login_jsp._jspService(login_jsp.java:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
tomcat提示以下错误:
数据库查询失败
[解决办法]
这是一个空指针引用错误
很可能是这里的rt返回了null值,查看下你的sql确实能够返回数据
并且query正确无误
ResultSet rt;
rt=jdbc.query(sql);
while(rt.next())