空指针错误,比如你在condiction.equals(cond1)前没有判断cnodiction是否为null,还有在while(!result.isAfterLast())前也要做是否为null的判断

解决方案 »

  1.   

    对象为null而又没有捕获错误
    可能出在:
    String condiction=request.getParameter("condiction");
    String Qvalue=request.getParameter("value");
    仔细检查参数名称condiction,value是否正确!建议用return断点检查!
      

  2.   

    NullPointerException一般因为对为null的对象做了什么操作而抛出,另外,你的程序中while(result.isAfterLast())不太对吧,一个查询出的ResultSet对象首先调用一次next()才能指向第一条记录,写成while(result.next()){}就行了
      

  3.   

    to wxbhlj(波波):请问怎么加判断啊?我加了还是不行啊?
      

  4.   

    我只是做例子而已,却为什么会这样啊?真的烦死了人了!to Shooter:我的while语句没有错误,我在别的一个分页显示的例子就是这样读的,这没有错误!to 红透半边天:那些变量名没有错啊!我现在真的知道该怎么办啊?请高手帮帮忙啊???
      

  5.   

    可能你取得值,其中有null。用之前先判断。
      

  6.   

    你把那个JSP代码改成下面的就行了:
    <%@ page contentType="text/html;charset=gb2312"%>
    <%@ page language="java"%><%@ page import="QueryBean"%>
    <jsp:useBean id="QueryBean" class="QueryBean" scope="session"/>
    <jsp:setProperty name="QueryBean" property="*"/><%@ page import="java.io.*"%>
    <%@ page import="java.util.*"%>
    <%@ page import="java.util.Date"%>
    <%@ page import="java.sql.*"%>
    <%@ page import="java.net.*"%><%
    String cond1="课程名称";
    String cond2="课程编号";
    String condiction=request.getParameter("condiction");
    String Qvalue=request.getParameter("value");
    String sql="select * from T_jxTeachScheme where ";
    if (condiction==null && Qvalue==null)
    {
    sql=null;
    }
    else
    {
    condiction=condiction.trim();
    Qvalue=Qvalue.trim();
     if (condiction.equals(cond1))
    {
    sql+=" fCName_China like '"+Qvalue+"' ";
    }
    else if (condiction.equals(cond2))
    {
    sql+=" fCourse_Num like '"+Qvalue+"' ";
    }
    }
    ResultSet result=null;
    if (sql!=null)
    {
    result=QueryBean.Query(sql);
    }
    %><html>
    <head>
    <title>课程查询系统</title>
    </head>
    <body bgcolor="#3399ff">
    <center>
    <font face="华文行楷" color="#00ffff" size="+6">课程查询系统</font>
    <hr size="3" color="#ffffff">
    <form action="Course.jsp" method="post">
    <table width="80%">
    <tr>
    <td width="80%">
    <font face="华文行楷" color="#ff0000">查询条件一:</font>
    <select name="condiction">
    <option>&nbsp;</option>
    <option>课程名称</option>
    <option>课程编号</option>
    </select>
    <font face="华文行楷" color="#ff0000">查询内容:</font>
    <input type="Text" name="value">
    </td>
    <td width="20%"><input type="Submit" value="查询"></td>
    </tr>
    </table>
    </form>
    <hr size="3" color="#ffffff">
    <font face="华文行楷" color="#ffffff" size="+3">查询结果如下表:</font>
    <table border="1" cellspacing="2" cellpadding="2" width="80%">
    <tr bgcolor="#00ffff">
    <td width="30%"><center><font face="华文行楷" size="+2" color="#ff0000">课程编号</font></center></td>
    <td width="70%"><center><font face="华文行楷" size="+2" color="#ff0000">课程名称</font></center></td>
    </tr>
    <%
    if (result!=null)
    {
    while(!result.isAfterLast())
    {
    %>
    <tr>
    <td width="30%"><center><%=result.getString("fCourse_Num")%></center></td>
    <td width="70%"><center><%=result.getString("fCName_China")%></center></td>
    </tr>
    <%
    result.next();
    }
    result.close();
    }
    %>
    </table>
    </center>
    <hr size="3" color="#ffffff">
    <%@ include file="FootIndex.jsp"%>
    </body>
    </html>