(1)org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 18 in the jsp file: /jdbcMySQL.jsp
The method creatStatement() is undefined for the type Connection
15: Class.forName(DBDRIVER);
16: conn =
17: DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
18: Statement stmt = conn.creatStatement();
19: String sql = "CREATE TABLE NAME (name varchar(32))";
20: stmt.executeUpdate(sql);
21: stmt.close();org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 18 in the jsp file: /jdbcMySQL.jsp The method creatStatement() is undefined for the type Connection 15: Class.forName(DBDRIVER); 16: conn = 17: DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD); 18: Statement stmt = conn.creatStatement(); 19: String sql = "CREATE TABLE NAME (name varchar(32))"; 20: stmt.executeUpdate(sql); 21: stmt.close();解决:可怕的低级错误,单词拼写错误(creatStatement();-->createStatement();)(2)org.apache.jasper.JasperException: Unable to compile class for JSP: //无法编译类JSP An error occurred at line: 44 in the jsp file: /jdbcMySQL.jsp Syntax error on token "catch", finally expected 41: stmt.close(); 42: conn.close(); 43: } 44: catch 45: { 46: 47: } //(Exception e)(3)org.apache.jasper.JasperException: An exception occurred processing JSP page /jdbcMySQL.jsp at line 32 29: } 30: %> 31: <% 32: String name = rs.getString(1); 33: String title = rs.getString(2); 34: String content = rs.getString(3); 35: %>(4)An error occurred at line: 20 in the jsp file: /insertAction.jsp name cannot be resolved 17: conn = 18: DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD); 19: stmt= conn.createStatement(); 20: String sql = "insert user (name,title ,content ) values ('"+name+"','"+title+"','"+content+"')"; 21: stmt.executeUpdate(sql); 22: stmt.setString(1,name); 23: stmt.setString(2,title); // <% String name = request.getParameter("name"); String title = request.getParameter("title"); String content = request.getParameter("content"); %>这个要写在执行它们的前面,语句要分上线顺序执行的,原来以为在jsp中不会有这种情况(5)org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 27 in the jsp file: /insertAction.jsp The method setString(int, String) is undefined for the type Statement 24: stmt= conn.createStatement(); 2 5: String sql = "insert user (name,title ,content ) values ('"+name+"','"+title+"','"+content+"')"; 26: stmt.executeUpdate(sql); 27: stmt.setString(1,name); 28: stmt.setString(2,title); 29: stmt.setString(3,content); //Statement不能用参数传递,应该换成preparedStatement,就能实现了(6) org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 29 in the jsp file: /insertAction.jsp The method prapareStatement(String) is undefined for the type Connection 26: Class.forName(DBDRIVER); 27: conn = 28: DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD); 29: pstmt= conn.prapareStatement(sql); 30: String sql = "insert user (name,title ,content ) values ('"+name+"','"+title+"','"+content+"')"; 31: pstmt.executeUpdate(sql); 32: pstmt.setString(1,name); //又一次是代码拼写错误 pstmt= conn.prapareStatement(sql)--> pstmt= conn.prepareStatement(sql)(7) java.sql.SQLException: SQL String can not be NULL //由于设置的时候没有设置主键自动递增,重新设置了一下主键,就可以读进去值了(8) org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 60 in the jsp file: /jdbcMySQL.jsp name cannot be resolved 57: <td>内容</td> 58: </tr> 59: <tr> 60: <td><%=name%></td>a 61: <td><%=title%></td> 62: <td><%=content%></td> 63: </tr> //还是放的老错误,把定义的内容放在调用的前面就好了(9) java.lang.NullPointerException //空指向问题,在前面没有对报错地方所用东西进行定义,后者就行传值 rs = pstmt.executeQuery();因该把得到的结果放在结果集里面,没有定义,就没有调用了(10)org.apache.jasper.JasperException: Unable to compile class for JSP:An error occurred at line: 38 in the jsp file: /delete.jspType mismatch: cannot convert from int to ResultSet//类型不匹配,ResultSet不能转换35: sql = "DELETE FROM note WHERE id=?";36: pstmt.setInt(1,id) ;37: pstmt= conn.prepareStatement(sql);38: rs = pstmt.executeUpdate();39:40:41: }//在删除页里面不用对结果集rs进行处理,后面没有语句对rs的结果进行应用,所以不用定义rs = pstmt。prepareStatement(sql),而直接写pstmt.prepareStatement(sql)即可,并且下面不会对rs进行关闭了(11)java.lang.NullPointerException分布检验,看看到哪里不能再往下执行了,首先在id = Integer.parseInt(request.getParameter("id")) ;后面,看看id的值有没有被传过来,结果证明有System.out.println(id);可以传过来id的值在pstmt= conn.prepareStatement(sql);pstmt.setInt(1,id) ;后面就不能打印出id的值,把pstmt= conn.prepareStatement(sql);pstmt.setInt(1,id) ;互换位置,就可以执行了,个人理解是应先执行sql,然后在对传过来的id的值进行赋值(12) java.sql.SQLException: No value specified for parameter 1 //没有任何价值,指定参数1 //因为只是执行了sql语句,可是没有把在上一个页面得到的参数id传到?里面也就是1所对应的里面(13) java.sql.SQLException: Illegal operation on empty result set. //在空洞的结果集非法操作。 可能是在数据库中不能找到相应的字段对应的内容 if(rs.next()) { id = rs.getInt(1) ; name = rs.getString(2); title = rs.getString(3); content = rs.getString(4); } 添加一个if(rs.next()){}对下面字段进行查询就没有这个错误了(14) 点击修改的时候,没有把参数传进来,取而代之的是数据库中的字段名称,如下<form action="updateAction.jsp"> 作者:<input type="text" name="name" value="name"><br> 标题:<input type="text" name="title" value="title"><br> 内容:<textarea name="content" cols="30" rows="6" value="content"></textarea><br> <input type="submit" value="修改"> <input type="reset" value="重置"> </form> 这样做就是在value里面取得一个字符串的值,后来发现他取到的只是一个对应的字符串,在 这里应该结合java语言,把 相应的地段里面的数值打印出来,结果如下 <form action="updateAction.jsp"> 作者:<input type="text" name="name" value="<%=name%>"><br> 标题:<input type="text" name="title" value="<%=title%>"><br> 内容:<textarea name="content" cols="30" rows="6" value="<%=content%>"></textarea><br> <input type="submit" value="修改"> <input type="reset" value="重置"> </form>可是在内容里面还是没有值,想到内容:<textarea>是一个双标签,可以把内容的值传到他的双标签里面,如下 内容:<textarea name="content" cols="30" rows="6"><%=content%></textarea><br> 结果可以输出(15)org.apache.jasper.JasperException: An exception occurred processing JSP page /updateAction.jsp at line 23 20: String name = new String(request.getParameter("name").getBytes("iso-8859-1"),"gb2312"); 21: String title = new String (request.getParameter("title").getBytes("iso-8859-1"),"gb2312"); 22: String content = new String(request.getParameter("content").getBytes("iso-8859-1"),"gb2312"); 23: int id = Integer.parseInt(request.getParameter("id")) ; 24: %> 25: <% 26: try //应该对int转换的时候进行抛出异常(16)最后在提交修改留言的时候不能实现,检测id的时候发现没有, <input type="hidden" name="id" value="<%=id%>"> 最后在update.jsp中加入的上面一行代码,是在跳转之前的一个页面有一个可以传过来的id的值,这样就可以得到id的值了心得:写完了一个简单的留言板,但是起码可以实现功能,从这个基础开始,慢慢的往上面添加我新学的东西,再接再厉 (17)The server encountered an internal error () that prevented it from fulfilling this request. 代码拼写错误,connection中少写了一个c(18)在从数据库中的user中调出用户名和密码,和在表单里面传过来的值作比较,用到了if(rs.next())可是总是登录不成功 <% try { Class.forName(DBDRIVER); conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD); sql = "select username,password from user"; System.out.println(sql); pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); %><% if(rs.next()) { String user_name = rs.getString("username"); String pass_word = rs.getString("password"); if(user_name.equals(username) && pass_word.equals(password)){ %> <h3><center>登录成功,两秒后跳转到留言页面</center></h3> <% response.setHeader("refresh","2;URL=jdbcMySQL.jsp") ; %> <h3><center>如果不跳转,请点击<a href="jdbcMySQL.jsp">这里</center></a></h3><hr> <% }else{ %> <h3><center>登录失败</center></h3> <% response.setHeader("refresh","2;URL=failReLogin.jsp") ; %> <h3><center>如果不跳转,请点击<a href="failReLogin.jsp">这里</center></a></h3><hr> <% } }%>开始的时候是这样写的,用while的时候会罗列出N个成功的和不成功的,但是用if就执行数据库中的第一的语句,不考虑这种方法了<% try { Class.forName(DBDRIVER); conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD); sql = "select username,password from user where username='"+username+"'"; System.out.println(sql); pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); %><% if(!rs.next()) { %> 此用户不存在!!!!请<a href="register.jsp">注册</a>!! <% }else{ String user_name = rs.getString("username"); String pass_word = rs.getString("password"); if(user_name.equals(username) && pass_word.equals(password)){ %> <h3><center>登录成功,两秒后跳转到留言页面</center></h3> <% response.setHeader("refresh","2;URL=jdbcMySQL.jsp") ; %> <h3><center>如果不跳转,请点击<a href="jdbcMySQL.jsp">这里</center></a></h3><hr> <% }else{ %> <h3><center>登录失败</center></h3> <% response.setHeader("refresh","2;URL=failReLogin.jsp") ; %> <h3><center>如果不跳转,请点击<a href="failReLogin.jsp">这里</center></a></h3><hr> <% } }%>写成这样的话,就可以直接把用的那个字段直接调用进来,验证成功(19) 新发现,如下做法,可以避免上面的问题,可以根据本身的id自动增长查到我们要找的字段,所以以后多想想好的思路,多看看别人的设计思路。 int id = 0; sql = "select id,username,password,email from user where email='"+email+"'"; pstmt = conn.prepareStatement(sql); //pstmt.setString(3,email); rs = pstmt.executeQuery(); if(rs.next()){ id++; username = rs.getString(2); password = rs.getString(3); %>