首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

java.lang.NullPointerException错误

2012-01-28 
java.lang.NullPointerException异常%@pagelanguage java pageEncoding GBK %%@includefile ..

java.lang.NullPointerException异常
<%@   page   language= "java "     pageEncoding= "GBK "   %>
<%@   include   file= "../../common.jsp "   %>
<LINK   href=../../css/css.css   rel=stylesheet>
<style   type= "text/css ">
<!--
.STYLE1   {font-family:   Verdana,   Arial,   Helvetica,   sans-serif}
-->
</style>
<link   href= "../css/css.css "   rel= "stylesheet "   type= "text/css ">
<body   bgcolor= "#F4F2F2 "   topmargin= "4 ">
<br/>
<%   Database   dsm=new   Database();
        ResultSet   rs=null;
        int   N_id=0;
        String   USER_name= " ";
        String   sqlStr= " ";
        String   N_sign= " ";
        String   N_addDate= " ";
        String   N_addUser= " ";
        String   N_title= " ";
        String   N_content= " ";
        String   N_sort= " ";
        String   S_id= " ";
        String   P_id= " ";
%>

<%
      N_id=3;
      System.out.println(N_id);
      USER_name=(String)session.getAttribute( "USER_name ");
      sqlStr= "select   *   from   newsshow   where   N_id=3 ";
      //System.out.println(sqlStr);
     
      try{
      dsm.setSqlStr(sqlStr);
      dsm.executeQuery();
      rs=dsm.getRs();
      while(rs.next()){
          N_title=rs.getString( "N_title ");
          N_content=rs.getString( "N_content ");
          N_addDate=(rs.getString( "N_addDate ")).substring(0,19);
          N_addUser=rs.getString( "N_addUser ");
          N_sort=rs.getString( "S_name ");
          N_sign=rs.getString( "P_name ");
%>
<form   method= "POST "   name= "myform "   action= "../../servlet/SortAdd ">
<table   width= "700 "   height= "127 "   border= "0 "   align= "center "
cellpadding= "0 "   cellspacing= "1 "   bgcolor= "#BBB3AA ">
<tr   bgcolor= "FBF5F0 ">
<td   height= "30 "   colspan= "4 "   align= "center "> <font   color= "#CC0000 "> <b> 新闻类别信息修改
   
   
   
    </b> </font> </td>
</tr>
<tr   bgcolor= "#FFFFFF ">
<td   width= "89 "   height= "25 "   align= "center ">
<font   face= "Verdana,   Arial,   Helvetica,   sans-serif ">


&nbsp;&nbsp;新闻标题: </font>   &nbsp; </td>
    <td   colspan= "3 "> &nbsp;
                <input   name= "title "   type= "text "   id= "title "   size= "55 "   value= " <%=N_title   %> "> </td>
        </tr>
<tr   bgcolor= "#FFFFFF ">
<td   height= "25 "   align= "center "> 新闻类型: </td>
            <td   width= "234 "   height= "20 "   align= "left "   >   &nbsp;
           
                  <input   name= "N_sort "   type= "text "   id= "N_sort "   value= " <%=N_sort   %> "   size= "20 ">
              <input   type= "button "   name= "editsort "   value= "更改 "   onClick= "window.location= 'sortselect2.jsp ' "> </td>
        <td   width= "97 "   align= "center "> 添加时间: </td>
        <td   width= "275 "   align= "left "> &nbsp; <%=N_addDate   %> </td>
</tr>
<tr   bgcolor= "#FFFFFF ">
    <td   height= "25 "   align= "center "> 针对省份: </td>
            <td   height= "20 "   align= "left ">   &nbsp;
            <%
                P_id=(null==request.getParameter( "P_id ")? "00 ":request.getParameter( "P_id "));
                System.out.println(P_id);                
                if(!P_id.equals( "00 ")){
                      ResultSet   rs3=null;
                      String   sql3= "select   *   from   tb_pro   where   P_id= ' "+P_id+ " ' ";
                      try{
                      dsm.setSqlStr(sql3);
                      dsm.executeQuery();
                      System.out.println(sql3);
                      rs3=dsm.getRs();
                      while(rs3.next()){
                          N_sign=rs.getString( "P_name ");
                          System.out.println( "== "+N_sign);
                          session.setAttribute( "P_id ",P_id);


                      }
                      System.out.println(N_sign);
                      }
                      catch(Exception   ee){}
                }
              %>
                <input   name= "N_sign "   type= "text "   id= "N_sign "   value= " <%=N_sign   %> "   size= "20 ">
                <input   type= "button "   name= "editpro "   value= "更改 "   onClick= "window.location= 'proselect.jsp ' "> </td>
            <td   width= "97 "   height= "20 "   align= "center "> 添加作者: </td>
            <td   height= "20 "   align= "left "> &nbsp; <%=N_addUser   %> </td>
    </tr>
<tr   bgcolor= "#FFFFFF ">
    <td   height= "20 "   align= "center "> 新闻内容: </td>
            <td   height= "20 "   colspan= "3 "   align= "left "> &nbsp;&nbsp; <input   type= "hidden "   name= "content "     value= " <%=N_content   %> "> <iframe   src= '../../eWebEditor/ewebeditor.htm?id=content '   frameborder=0   scrolling=no   width= '550 '   HEIGHT= '350 '> </iframe> </td>
    </tr>
<tr   bgcolor= "#FFFFFF ">
    <td   height= "30 "   colspan= "4 "   align= "right "> <span   class= "STYLE1 ">
        <input   type= "submit "   name= "Submit2 "   value= "添加 ">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input   type= "reset "   name= "Submit "   value= "重置 ">
&nbsp;&nbsp;
&nbsp;&nbsp;  
<input   type= "button "   name= "Submit3 "   value= "返回 "   onClick= "javascript:history.go(-1); ">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> </td>
    </tr>
    </table>
<%}}catch(Exception   ew){System.out.println(ew.toString());}   %>
</form>
上面是我的JSP页面代码
00
3
4
select   *   from   tb_pro   where   P_id= '4 '
java.lang.NullPointerException
这是在控制台输出的结果
在传一个值过来后,能接到,也能执行SQL查询,但是一到rs(N_sign=rs.getString( "P_name ");)那里就走不下去了
哪位高手知道错误原因啊,帮帮忙!谢谢了!

[解决办法]
写错了吧,N_sign=rs3.getString( "P_name ");应该是rs3啊,还有把这些操作封装下吧,别把java代码和jsp页面耦合在一起,查错误很麻烦,最好分层
[解决办法]
N_sign=rs.getString( "P_name ");
这一句改为:


N_sign=rs3.getString( "P_name ");

热点排行