问题描述
typeExceptionreportmessagedescriptionTheserverencounteredaninternalerror()thatpreventeditfromfulfillingthisrequest.exceptionorg.apache.jasper.JasperException:AnexceptionoccurredprocessingJSPpage/reading.jspatline3431:<%32://通过传来的ID提取学生资料33:Connectionconn=linejdbc.getopenConnection();34:PreparedStatements=conn.prepareStatement("select*fromstudentwhereS_id=?andS_psw=?");35:s.setString(1,userNow);36:s.setString(2,password);37:ResultSetresult=s.executeQuery();Stacktrace:org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rootcausejava.lang.NullPointerExceptionorg.apache.jsp.reading_jsp._jspService(reading_jsp.java:106)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:374)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/6.0.18logs.
解决方案
解决方案二:
数据库连接文件:packagedata;importjava.util.*;importjava.sql.*;importjava.io.*;publicclassDBConnectionBean{Connectiondbcon=null;Statementstmt=null;ResultSetresult=null;Stringdriver="";Stringurl="";Stringuser="";Stringpassword="";publicDBConnectionBean(){try{//读取配置文件InputStreamfis=getClass().getResourceAsStream("jdbcsql.properties");Propertiesps=newProperties();ps.load(fis);driver=ps.getProperty("driver");url=ps.getProperty("url");user=ps.getProperty("username");password=ps.getProperty("password");Class.forName(this.driver);}/*try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Stringurl="jdbc:odbc:exam";Connectionconn=DriverManager.getConnection(url,"sa","123");*/}catch(Exceptione){System.out.println(e);}}publicvoidsetdrivername(){try{Class.forName(this.driver);System.out.println("���������ɹ�!");}catch(ClassNotFoundExceptione){System.out.println("jdbcdrivererror");}}publicConnectiongetopenConnection(){try{this.dbcon=DriverManager.getConnection(this.url,this.user,this.password);System.out.println("�Ž���ݿ�ɹ�!");}catch(SQLExceptione2){System.out.println(e2);}returndbcon;}publicResultSetexecuteQuery(Stringquery)throwsSQLException{this.stmt=dbcon.createStatement();this.result=stmt.executeQuery(query);returnresult;}publicvoidexecuteUpdate(Stringquery)throwsSQLException{this.stmt=dbcon.createStatement();stmt.executeUpdate(query);if(stmt!=null)stmt.close();}publicStringgetData(intindex)throwsSQLException{returnresult.getString(index);}publicintgetIntData(intindex)throwsSQLException{returnresult.getInt(index);}publicfloatgetFltData(intindex)throwsSQLException{returnresult.getFloat(index);}publicbooleannext()throwsSQLException{returnresult.next();}publicvoidresetResult()throwsSQLException{this.result=null;}publicvoidclose()throwsSQLException{if(dbcon!=null)dbcon.close();if(stmt!=null)stmt.close();if(result!=null)result.close();}publicvoidfinalize()throwsThrowable{this.close();}publicStringreplaceString(Stringstr){chartempArray[]=str.toCharArray();intiCurr[]=newint[10];intj=0;for(inti=0;i!=tempArray.length;i++){inttemp=(int)tempArray[i];if(temp==92){iCurr[j]=i;j++;}}finalinttemp2=j+1;StringstrArray[]=newString[temp2];strArray[0]=str.substring(0,iCurr[0]);strArray[temp2-1]=str.substring(iCurr[j-1]+1);for(intm=1;m!=strArray.length-1;m++){strArray[m]=str.substring(iCurr[m-1]+1,iCurr[m]);}str="";for(intk=0;k!=strArray.length-1;k++){str=str+strArray[k]+"%5C";}str=str+strArray[temp2-1];returnstr;}}
解决方案三:
jdbcsql.properties文件:driver=com.microsoft.jdbc.sqlserver.SQLServerDriverurl=jdbc:microsoft:sqlserver://local:1433;DatabaseName=examusername=cenjuhuipassword=123
解决方案四:
reading.jsp中空指向异常!!!看一下数据库连接是不是有问题啊!!
解决方案五:
31:<%32://通过传来的ID提取学生资料33:Connectionconn=linejdbc.getopenConnection();34:PreparedStatements=conn.prepareStatement("select*fromstudentwhereS_id=?andS_psw=?");35:s.setString(1,userNow);36:s.setString(2,password);37:ResultSetresult=s.executeQuery();你的ID呢?是不是没写还是出现转换错误Stringid=request.getParameter("id");Integeruid=Integer.parInt(id);像这样的代码你写了没?我怀疑是这里的问题最好是把代码贴出来
解决方案六:
一楼就是错误!二楼是原码!
解决方案七:
<%@pagecontentType="text/html;charset=gb2312"language="java"import="data.*"import="java.sql.*"import="java.io.*"import="java.util.*"import="java.lang.*"%><%request.setCharacterEncoding("gb2312");%><html><head><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"><title>准备答题</title><linkhref="img/cssexamin.css"rel="stylesheet"type="text/css"><scriptlanguage="JavaScript"type="text/JavaScript"src="/myside/examin/img/youno.js"></script><styletype="text/css"><!--.style1{color:#FF0000}.unnamed1{font-size:12px;color:#FF0000;text-decoration:none;}--></style></head><body><divalign="center"><jsp:useBeanid="linejdbc"scope="page"class="data.DBConnectionBean"/><%StringuserNow=request.getParameter("userid");Stringpassword=request.getParameter("password");System.out.print(password);%><%linejdbc.setdrivername();%><%//通过传来的ID提取学生资料Connectionconn=linejdbc.getopenConnection();PreparedStatements=conn.prepareStatement("select*fromstudentwhereS_id=?andS_psw=?");s.setString(1,userNow);s.setString(2,password);ResultSetresult=s.executeQuery();if(result.next()){StringS_id=result.getString("S_id");StringS_name=result.getString("S_name");StringSex=result.getString("sex");StringMajor=result.getString("major");StringGrade=result.getString("grade");%><%//随机在学生所要考的科目中提取题库的IDintromad=0;intt=0;inti=0;Connectionconnn=linejdbc.getopenConnection();PreparedStatementp=connn.prepareStatement("selectMAX(id)fromquiz");ResultSetresultp=p.executeQuery();resultp.next();t=resultp.getInt(1);Randomrand=newRandom();i=rand.nextInt(t);romad=i+1;%><formaction="begin.jsp"method="post"name="formzhunbei"id="formzhunbei"><spanclass="unnamed1">登陆成功!</span><tablewidth="360"border="0"cellpadding="0"cellspacing="2"><tr><tdcolspan="2"><pclass="table">您的相关信息:</p></td></tr><tr><tdwidth="48%"class="table">学号:<%=userNow%></td><tdwidth="52%"class="table">姓名:<%=S_name%></td></tr><tr><tdclass="table">性别:<%=(Sex==null?"":Sex)%></td><tdclass="table">年级:<%=(Grade==null?"":Grade)%></td></tr><tr><tdcolspan="2"class="table">专业:<%=(Major==null?"":Major)%><inputname="S_id"type="hidden"id="S_id"value="<%=S_id%>"><inputname="S_name"type="hidden"id="S_name"value="<%=S_name%>"></td></tr><%s=conn.prepareStatement("select*fromscorewheres_id=?");s.setString(1,userNow);ResultSetrs=s.executeQuery();if(rs.next()){%><tr><tdcolspan="2"class="table">你已经参加过考试了,你的上次考试成绩为:<%=rs.getInt("score")%></td></tr><%}%><tr><tdcolspan="2"><palign="center"class="unnamed1">警告:</p><palign="center"class="unnamed1">答题过程不能中断!如果您试图进行作弊或者超过答题时间,</p><palign="center"class="unnamed1">您将被强令在24小时后进行补考,补考时间到期前,您不能参加考试!</p><palign="center"class="banquan">如果您准备完毕,点按钮开始答题!</p><palign="center"><inputtype="image"border="0"src="img/zhunbei.gif"align="准备完毕"width="97"height="38"onClick="formzhunbei.submit()"name="image"></p></td></tr></table><pclass="banquan"> </p></form><p> </p><p> </p></div><%}else{out.print("<spanclass='unnamed1'>用户ID不存在或密码错误!<br><ahref='login.jsp'target='_self'>返回</a></span>");}%></body></html>
解决方案八:
connection对象获得没有?在调用它的方法的时候报了空指针!linejdbc.getopenConnection();linejdbc实例化没有,如果没有实例化,就读取不了配置文件,connection对象也无从获得!
解决方案九:
linejdbc.getopenConnection();得到null了,连不上数据库控制台的出错信息呢?
解决方案十:
java.lang.NullPointerExceptionjava.lang.NullPointerException11jdbcdrivererror11jdbcdrivererrorjava.sql.SQLException:Nosuitabledriverfoundforjava.sql.SQLException:Nosuitabledriverfoundfor2009-5-1413:20:09org.apache.catalina.core.StandardWrapperValveinvoke严重:Servlet.service()forservletjspthrewexceptionjava.lang.NullPointerExceptionatorg.apache.jsp.reading_jsp._jspService(reading_jsp.java:106)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)atjava.lang.Thread.run(UnknownSource)2009-5-1413:20:09org.apache.catalina.core.StandardWrapperValveinvoke严重:Servlet.service()forservletjspthrewexceptionjava.lang.NullPointerExceptionatorg.apache.jsp.reading_jsp._jspService(reading_jsp.java:106)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)atjava.lang.Thread.run(UnknownSource)
解决方案十一:
<jsp:useBeanid="linejdbc"scope="page"class="data.DBConnectionBean"/>
解决方案十二:
楼主,这个问题你搞定了没有?
解决方案十三:
java.lang.NullPointerExceptionjava.lang.NullPointerException11jdbcdrivererror11jdbcdrivererrorjava.sql.SQLException:Nosuitabledriverfoundforjava.sql.SQLException:Nosuitabledriverfoundfor貌似驱动问题,是不是驱动版本问题或者干脆没找到驱动