错误1: 将<%@ page import="java.sql.*"%>  改为<%@ page import="java.sql.*,java.io.*"%>      说明:你需要导入java.io.*这个包,因为IOException在io包内错误2.3:把你方法的内容都放在
try{
    放这里
    }catch(Exception e)
          {System.out.println(e);}

解决方案 »

  1.   

    <%@ page import="java.sql.*"%>
    <%@ page import="java.io.*"%>
      

  2.   

    biggie(飞碟) :
    我太崇拜你了。你就是我的偶像。这个问题解决了。但是有新的报错信息:---------------------------------------------------------------------
    java.lang.ArithmeticException: / by zero
    at _program._new._quexian._qxdji__jsp._jspService(D:\resin-2.1.6\doc\program\new\quexian\qxdji.jsp:55)
    at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
    at com.caucho.jsp.Page.subservice(Page.java:497)
    at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
    at com.caucho.server.http.Invocation.service(Invocation.java:312)
    at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:244)
    at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
    at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
    at java.lang.Thread.run(Thread.java:536)
    ------------------------------------------------------------------------------还请你再帮我分析。谢谢你!!!!
      

  3.   

    楼上的可不可以具体点。55行:intPageCount=(totalSub/totalSubPerPage * 10 + 5)/10 ;
      

  4.   

    biggie(飞碟):你好!
    我把问题从新说一下:<%@ page contentType="text/html;charset=gb2312"%>  
     <%@ page import="java.sql.*"%>
    <%@ page import="java.io.*"%>
    <%@ include file="../session.jsp"%>
    <html>
    <head><title>缺陷登记
    </title>
    <link rel=stylesheet href="style.css" type="text/css">
    <script language="JavaScript">
    function newwin(url) {
      var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450");
      newwin.focus();
      return false;
    }
    </script>
    </head>
    <body>
    <script LANGUAGE="javascript">
    function submit11()
    {
    self.location.replace("qxdji.jsp")
    }
    </script>
    <jsp:useBean id="bbsBean" scope="page" class="firm.firm" />
    <%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
    String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=MyDatabase"; 
    //pubs为你的数据库的 
    String user="sa"; 
    String password=""; 
    Connection conn= DriverManager.getConnection(url,user,password); 
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); int pageLine=10;
    int totalRec=0;
    int totalSub=0;
    int intPage=1;
    if (request.getParameter("page")!=null)
    intPage=Integer.parseInt(request.getParameter("page"));
    try{String sql="select count(*) as cnt from board"; 
    ResultSet rs=stmt.executeQuery(sql); //指定参考行数
    //取得总数
    if (rs.next())
     totalRec=rs.getInt("cnt");
    //取得主题数
    String sql2="select count(*) as cnt from board"; 
    ResultSet rs2=stmt.executeQuery(sql2); 
    if (rs2.next())
     totalSub=rs2.getInt("cnt");
    }
    catch(Exception e){
       e.printStackTrace();
    }
    //取得每行的主题数量
    int jtemp=totalRec/pageLine+1;
    int totalSubPerPage=totalSub/jtemp;
    //取得总页数
    int intPageCount=0;
    intPageCount=(totalSub/totalSubPerPage * 10 + 5)/10 ;
    %>
    <center><font color="blue"><h4>设备缺陷登记管理</h4></font>
    <%
    out.print("<table border='1' cellspacing='0' width='632' bgcolor='#d7e3b9' bordercolorlight='#green' bordercolordark='#ECF5FF'>");
    out.print("<tr align='center' bgcolor='#c8cc98'>");
    out.print("<td width='240'>标题</td>");
    out.print("<td width='60'>发表人</td>");
    //out.print("<td width='100'>发表时间</td>");
    out.print("<td width='40'>状态</td>");
    out.print("<td width='40'>管理</td>");
    out.print("</tr>");
    %>
    <%
    String serial;
    String title;
    String recorder;
    //Date providedate;String sql3="select * from board where parent_no=0 order by serial_no DESC"; 
    ResultSet rs3=stmt.executeQuery(sql3); int i=0;  
    while (rs3.next()) {
       i++;//-----------------显示本级的帖子内容
       if (i>(totalSubPerPage *(intPage-1)) && (i<=(intPage * totalSubPerPage))){
         out.print("<tr><td>");
         serial=rs3.getString("serial_no");
         title=rs3.getString("title");
        recorder=rs3.getString("recorder");
         //providedate=RS.getDate("time");
        // showing(request,out,serial,title,recorder,providedate,"Subject");
    showing(request,out,serial,title,recorder,"Subject");
       //-----------------显示下一级的回复内容
       
       String sql4="select * from board where parent_no=" + serial + " order by serial_no"; 
    ResultSet rs4=stmt.executeQuery(sql4); 
       
       
         while (rs4.next()) {
           out.print("<tr><td>");
           serial=rs4.getString("serial_no");
           title=rs4.getString("title");
          recorder=rs4.getString("recorder");
          // providedate=RS1.getDate("time");
           //showing(request,out,serial,title,recorder,providedate,"Re");
    showing(request,out,serial,title,recorder,"Re");
         }
       //------------------------
      }
     } %> 
    <!--以下函数用于帖子内容显示 -->
    <%!
      void showing(HttpServletRequest request,JspWriter out,String serial,String title,String recorder, String ReSign)
      throws IOException {
      try{  if(ReSign=="Subject"){
         out.print("<a href=bbsAnswer.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
      }
      else{
         out.print("<a href=bbsReply.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
      }
      out.print("</td><td align='center'>");
      out.print(recorder);
      out.print("</td></tr>");
      }catch(Exception e)
              {System.out.println(e);}}
    %>
    <!--以下用于帖子分页显示 -->
    <%
     out.print("<tr>");  
     if (intPageCount*pageLine<totalRec) 
       intPageCount++;
     if (intPage>intPageCount )
    intPage=intPageCount;
     if (intPage < 1 )
    intPage=1;
    out.print("<form method='POST'  name=fPageNum  action='qxdjj.jsp'>");
    out.print("<p align='left'>&gt;&gt;分页&nbsp;");
      
       if (intPage<2)
         out.print("<font color='999966'>首页 上一页</font>&nbsp;");
       else{   
       out.print("<a href='qxdjj.jsp?page=1'>首页</a>&nbsp;");   
         out.print("<a href='admin_user.jsp?page=" + (intPage-1) + "'>上一页</a>&nbsp;"   );
         }
      
         
       if( intPage-intPageCount>=0 )
         out.print("<font color='999966'>下一页 尾页</font>"   );
       else{   
      
         out.print("<a href='admin_user.jsp?page=" + (intPage+1)+ "'>下一页</a> <a href='qxdjj.jsp?page=" + intPageCount + "'>尾页</a>");
         }
     
            out.print("&nbsp;页次:<strong><font color=red>"+intPage+"</font>/"+intPageCount+"</strong>页 "   );
        out.print("&nbsp;共<b>"+totalRec+"</b>条记录 <b>"+pageLine+"</b>条/页 "   );
        out.print(" 转到第<input type='text' name='page' size=2 maxlength=10 class=smallInput value="+intPage+">");   
        out.print("页<input class=buttonface type='submit'  value='GO'  name='cndok'></span></p></form>"  );  out.print("</td>");
    out.print("</tr>"); 

    %>
    </table></p>
    <a href="javascript:window.close();">[关闭]</a>
    </center>
    <% 
    rs.close(); 
    rs2.close(); 
    rs3.close(); 
    rs4.close(); 
    stmt.close(); 
    conn.close();  %>
    </body>
    </html>----------------------------------报错信息------------------------------------Note: sun.tools.javac.Main has been deprecated.
    D:\resin-2.1.6\doc\program\new\quexian\qzdjj.jsp:186: Undefined variable
    or class name: rs
    rs.close(); 
    ^
    D:\resin-2.1.6\doc\program\new\quexian\qzdjj.jsp:187: Undefined variable
    or class name: rs2
    rs2.close(); 
    ^
    D:\resin-2.1.6\doc\program\new\quexian\qzdjj.jsp:189: Undefined variable
    or class name: rs4
    rs4.close(); 
    ^
    3 errors, 1 warning----------------------------------------------------------------------------请帮我分析一下。谢谢!
      

  5.   

    作用域问题
    在{ 这里定义的东西,只对这内生效} 在外面不生效
    所以你最后的rs2.rs3.rs4都会提示你没有定义的错误解决方法
        把你的rs2.rs3.rs4在你应用完成后的作用域内关闭掉就可以了,不用在最后关闭在最后只把conn和stmt关掉就行
      

  6.   

    你的rs1,rs2...不是全局变量,不在作用域内rs.close(),肯定会报没有定义的错误,方法1用biggie(飞碟) 的说法,方法2在对rs操作前定义变量,ResultSet rs1=null;ResultSet rs2=null;.....
      

  7.   

    biggie(飞碟):你好!
    我把问题从新说一下:<%@ page contentType="text/html;charset=gb2312"%>  
     <%@ page import="java.sql.*"%>
    <%@ page import="java.io.*"%>
    <%@ include file="../session.jsp"%>
    <html>
    <head><title>缺陷登记
    </title>
    <link rel=stylesheet href="style.css" type="text/css">
    <script language="JavaScript">
    function newwin(url) {
      var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450");
      newwin.focus();
      return false;
    }
    </script>
    </head>
    <body>
    <script LANGUAGE="javascript">
    function submit11()
    {
    self.location.replace("qxdji.jsp")
    }
    </script>
    <jsp:useBean id="bbsBean" scope="page" class="firm.firm" />
    <%
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
    String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=MyDatabase"; 
    //pubs为你的数据库的 
    String user="sa"; 
    String password=""; 
    Connection conn= DriverManager.getConnection(url,user,password); 
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); int pageLine=10;
    int totalRec=0;
    int totalSub=0;
    int intPage=1;
    if (request.getParameter("page")!=null)
    intPage=Integer.parseInt(request.getParameter("page"));
    try{
    String sql="select count(*) as cnt from board"; 
    ResultSet rs=stmt.executeQuery(sql); 
    //指定参考行数
    //取得总数
    if (rs.next())
     totalRec=rs.getInt("cnt");
     rs.close(); 
    //取得主题数
    String sql2="select count(*) as cnt from board"; 
    ResultSet rs2=stmt.executeQuery(sql2); 
    if (rs2.next())
     totalSub=rs2.getInt("cnt");
    rs2.close(); 
    }
    catch(Exception e){
       e.printStackTrace();
    }
    //取得每行的主题数量
    int jtemp=totalRec/pageLine+1;
    int totalSubPerPage=totalSub/jtemp;
    //取得总页数
    int intPageCount=0;
    intPageCount=(totalSub/totalSubPerPage * 10 + 5)/10 ;
    %>
    <center><font color="blue"><h4>设备缺陷登记管理</h4></font>
    <%
    out.print("<table border='1' cellspacing='0' width='632' bgcolor='#d7e3b9' bordercolorlight='#green' bordercolordark='#ECF5FF'>");
    out.print("<tr align='center' bgcolor='#c8cc98'>");
    out.print("<td width='240'>标题</td>");
    out.print("<td width='60'>发表人</td>");
    //out.print("<td width='100'>发表时间</td>");
    out.print("<td width='40'>状态</td>");
    out.print("<td width='40'>管理</td>");
    out.print("</tr>");
    %>
    <%
    String serial;
    String title;
    String recorder;
    //Date providedate;
    String sql3="select * from board where parent_no=0 order by serial_no DESC"; 
    ResultSet rs3=stmt.executeQuery(sql3); 
    int i=0;  
    while (rs3.next()) {
       i++;//-----------------显示本级的帖子内容
       if (i>(totalSubPerPage *(intPage-1)) && (i<=(intPage * totalSubPerPage))){
         out.print("<tr><td>");
         serial=rs3.getString("serial_no");
         title=rs3.getString("title");
        recorder=rs3.getString("recorder");
         //providedate=RS.getDate("time");
        // showing(request,out,serial,title,recorder,providedate,"Subject");
    showing(request,out,serial,title,recorder,"Subject");
       //-----------------显示下一级的回复内容
     String sql4="select * from board where parent_no=" + serial + " order by serial_no"; 
     ResultSet rs4=stmt.executeQuery(sql4); 
     while (rs4.next()) {
           out.print("<tr><td>");
           serial=rs4.getString("serial_no");
           title=rs4.getString("title");
          recorder=rs4.getString("recorder");
          // providedate=RS1.getDate("time");
           //showing(request,out,serial,title,recorder,providedate,"Re");
    showing(request,out,serial,title,recorder,"Re");
         }
       rs4.close(); 
      }
     } 
    rs3.close(); 
    %> 
    <!--以下函数用于帖子内容显示 -->
    <%!
      
      void showing(HttpServletRequest request,JspWriter out,String serial,String title,String recorder, String ReSign)
      throws IOException {
      try{
      if(ReSign=="Subject"){
         out.print("<a href=bbsAnswer.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
      }
      else{
         out.print("<a href=bbsReply.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
      }
      out.print("</td><td align='center'>");
      out.print(recorder);
      out.print("</td></tr>");
      }
    catch(Exception e)
              {System.out.println(e);}
    }
    %>
    <!--以下用于帖子分页显示 -->
    <%
     out.print("<tr>");  
     if (intPageCount*pageLine<totalRec) 
       intPageCount++;
     if (intPage>intPageCount )
    intPage=intPageCount;
     if (intPage < 1 )
    intPage=1;
    out.print("<form method='POST'  name=fPageNum  action='qxdjj.jsp'>");
    out.print("<p align='left'>&gt;&gt;分页&nbsp;");
       if (intPage<2)
         out.print("<font color='999966'>首页 上一页</font>&nbsp;");
       else{   
       out.print("<a href='qxdjj.jsp?page=1'>首页</a>&nbsp;");   
         out.print("<a href='qzdjj.jsp?page=" + (intPage-1) + "'>上一页</a>&nbsp;"   );
         }
       if( intPage-intPageCount>=0 )
         out.print("<font color='999966'>下一页 尾页</font>"   );
       else{   
      
         out.print("<a href='qzdjj.jsp?page=" + (intPage+1)+ "'>下一页</a> <a href='qxdjj.jsp?page=" + intPageCount + "'>尾页</a>");
         }
            out.print("&nbsp;页次:<strong><font color=red>"+intPage+"</font>/"+intPageCount+"</strong>页 "   );
        out.print("&nbsp;共<b>"+totalRec+"</b>条记录 <b>"+pageLine+"</b>条/页 "   );
        out.print(" 转到第<input type='text' name='page' size=2 maxlength=10 class=smallInput value="+intPage+">");   
        out.print("页<input class=buttonface type='submit'  value='GO'  name='cndok'></span></p></form>"  );  out.print("</td>");
    out.print("</tr>"); 
    %>
    </table></p>
    <a href="javascript:window.close();">[关闭]</a>
    </center>
    <% 
    stmt.close(); 
    conn.close();  %>
    </body>
    </html>-------------------------------------------------------------------------------
    java.lang.NullPointerException
    at com.microsoft.jdbc.base.BaseResultSet.cancelPendingUpdates(Unknown Source)
    at com.microsoft.jdbc.base.BaseResultSet.next(Unknown Source)
    at _program._new._quexian._qxdjj__jsp._jspService(D:\resin-2.1.6\doc\program\new\quexian\qxdjj.jsp:84)
    at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
    at com.caucho.jsp.Page.subservice(Page.java:497)
    at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
    at com.caucho.server.http.Invocation.service(Invocation.java:312)
    at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:244)
    at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
    at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
    at java.lang.Thread.run(Thread.java:536)-----------------------------------------------------------------------------其中84行是:     while (rs3.next()) {
      

  8.   

    if (i>(totalSubPerPage *(intPage-1)) && (i<=(intPage * totalSubPerPage))){
    在这句之前加一个
    System.out.println("OK");
    看一看控制台能不能打出来,如果能的话说明你sql3能取出值,如果不能的话,那就说明没取出值如果显示ok那么注释掉showing(request,out,serial,title,recorder,"Subject");
    试试是否正常,然后在找问题原因--------题外话:你怎么能这么写程序呢?换个方式去写,这么写很拉圾,而且不容易查错
      

  9.   

    我在IF语句之前加System.out.println("OK");但是调试信息和以前一样。还有我不知道控制台是什么?不好意思。我初级哦。呵呵。还有你说的换个方式。可以说的具体点吗?