问题描述
为什么我明明定义了方法,还回出现错误??包contorl下有两个类,一个accessdb类,一个words类继承accessdb;而在jsp调用words这个javabean但是出现我没定义方法为什么???accessdb源代码:packagecontrol;importjava.sql.*;publicclassaccessdb{Connectioncon;Statementstmt;ResultSetrs;publicvoidaccessdb(){stmt=null;rs=null;}publicbooleangetconn(){try{Class.forName("sun,jdbc.odbc.JdbcOdbcDriver");con=DriverManager.getConnection("jdbc:odbc:student");returntrue;}catch(SQLExceptionex){System.out.println(ex.toString());returnfalse;}catch(ClassNotFoundExceptionex){System.out.print(ex);returnfalse;}}publicbooleanexeSql(StringstrSql){try{stmt=con.createStatement();stmt.executeUpdate(strSql);returntrue;}catch(Exceptionex){returnfalse;}}publicResultSetexeSqlQuery(StringstrSql){try{stmt=con.createStatement();rs=stmt.executeQuery(strSql);}catch(Exceptionex){System.out.println(ex.toString());rs=null;}returnrs;}publicvoidconclose(){try{con.close();}catch(Exceptionex){System.out.println(ex.toString());}}}jsp页面:<%@pagelanguage="java"contentType="text/html;charset=GB2312"pageEncoding="GB18030"%><%@pageimport="java.sql.*"%><jsp:useBeanclass="control.words"id="words"scope="page"/><html><head><metahttp-equiv="Content-Type"content="text/html;charset=GB2312"><title>Inserttitlehere</title></head><body><%if(words.getconn()){out.println("connectedsuccessfull!");}else{out.println("connectedfaild!");}%></body></html>错误代码:HTTPStatus500---------------------------------------------------------------------------------typeExceptionreportmessagedescriptionTheserverencounteredaninternalerror()thatpreventeditfromfulfillingthisrequest.exceptionorg.apache.jasper.JasperException:UnabletocompileclassforJSP:Anerroroccurredatline:12inthejspfile:/b.jspThemethodgetconn()isundefinedforthetypewords9:</head>10:<body>11:<%12:if(words.getconn())13:{14:out.println("connectedsuccessfull!");15:}Stacktrace:org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)javax.servlet.http.HttpServlet.service(HttpServlet.java:803)noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/6.0.10logs.为什么我明明定义了????
解决方案
本帖最后由 hjl317834478 于 2011-01-07 21:37:05 编辑
解决方案二:
你的类为accessdb而你的jsp种<jsp:useBeanclass="control.words"id="words"scope="page"/>你哪来的words类
解决方案三:
<jsp:useBeanclass="control.accessdb"id="words"scope="page"/>