jxj0017 2009-07-21 10:29
浏览 215
已采纳

很菜的jsp问题,困惑一天了。

本人学习java一个多月,很多东西都不知道。今天做一个管理系统,用户能够完成注册,登陆功能,但设备信息就是无法显示,系统报空指针异常,但我仔细检查了程序,没有发现什么问题,数据库中也有数据,既然能够注册登录,肯定不是数据库连接问题,下面是代码:


Dao类中的查询设备信息的方法

 

public java.util.List<E_CPUInformation> getAllE_CPUInformation(){
        java.util.List<E_CPUInformation> E_CPUInformationList=new java.util.ArrayList();
        String sql="SELECT * FROM equipment_CPU";
       
        try
        {
           
            Connection con=getConn();
            java.sql.PreparedStatement pstm=con.prepareStatement(sql);
            java.sql.ResultSet rs=pstm.executeQuery();         //执行sql语句
           
            while(rs.next())
            {
                E_CPUInformation eci=new E_CPUInformation();
                eci.setEquipment_CPU_id(rs.getString(1));
                eci.setEquipment_CPU_model(rs.getString(2));
                eci.setEquipment_CPU_CoreCode(rs.getString(3));
                eci.setEquipment_CPU_SN(rs.getString(4));
                eci.setEquipment_CPU_socket(rs.getString(5));
                eci.setEquipment_CPU_FSB(rs.getString(6));
                eci.setEquipment_CPU_Level2Cache(rs.getString(7));
                eci.setEquipment_CPU_SPEED(rs.getString(8));
                eci.setEquipment_CPU_version(rs.getString(9));
                eci.setEquipment_CPU_status(rs.getString(10));
                eci.setEquipment_CPU_custodian(rs.getString(11));
                eci.setEquipment_CPU_lender(rs.getString(12));
                eci.setEquipment_CPU_lenddate(rs.getString(13));
                eci.setEquipment_CPU_expectreturndate(rs.getString(14));
                eci.setEquipment_CPU_returndate(rs.getString(15));
                eci.setEquipment_CPU_lendhonor(rs.getString(16));
                eci.setEquipment_CPU_remark1(rs.getString(17));
                eci.setEquipment_CPU_remark2(rs.getString(18));
                eci.setEquipment_CPU_remark3(rs.getString(19));
            }
            rs.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
         return E_CPUInformationList;
    }

对应Action类

 

package advantechEMS.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import advantechEMS.db.DaoE_CPUInformation;
import advantechEMS.db.E_CPUInformation;
import advantechEMS.db.User;

public class SelectE_CPUAction implements ActionInterface{
   
    public String execute(HttpServletRequest request,HttpServletResponse response)
    {
       
        DaoE_CPUInformation dbi=new DaoE_CPUInformation();
        java.util.List<E_CPUInformation> E_CPUInformationList=dbi.getAllE_CPUInformation();
        request.getSession().setAttribute("E_CPUInformationList",E_CPUInformationList);     
       
        return "/E_CPUInformation.jsp";
       
    }

}

    对应JSP部分文件

 

<tbody>
    <tr>
        <th>CPU_id</th>
        <th>CPU_model</th>
        <th>CPU_CoreCode</th>
        <th>CPU_SN</th>
        <th>CPU_socket</th>
        <th>CPU_FSB</th>
        <th>CPU_Level2Cache</th>
        <th>CPU_SPEED</th>
        <th>CPU_version</th>
        <th>CPU_status</th>
        <th>CPU_custodian</th>
        <th>CPU_lender</th>
        <th>CPU_lenddate</th>
        <th>CPU_expectreturndate</th>
        <th>CPU_returndate</th>
        <th>CPU_lendhonor</th>
        <th>CPU_remark1</th>
        <th>CPU_remark2</th>
        <th>CPU_remark3</th>
       
    </tr>
</tbody>

<tbody>
<%

java.util.List<E_CPUInformation> E_CPUInformationList =(List)session.getAttribute("E_CPUInformationList");//从session中取出数据,并定义为list
  for(int i=0;i<E_CPUInformationList.size();i++){
      E_CPUInformation eci=E_CPUInformationList.get(i);
  
%>
 
<tr>
<td><%=eci.getEquipment_CPU_id()%></td>
<td><%=eci.getEquipment_CPU_model()%></td>
<td><%=eci.getEquipment_CPU_CoreCode()  %></td>
<td><%=eci.getEquipment_CPU_SN() %></td>
<td><%=eci.getEquipment_CPU_socket() %></td>
<td><%=eci.getEquipment_CPU_FSB() %></td>
<td><%=eci.getEquipment_CPU_Level2Cache() %></td>
<td><%=eci.getEquipment_CPU_SPEED() %></td>
<td><%=eci.getEquipment_CPU_version() %></td>
<td><%=eci.getEquipment_CPU_status() %></td>
<td><%=eci.getEquipment_CPU_custodian() %></td>
<td><%=eci.getEquipment_CPU_lender() %></td>
<td><%=eci.getEquipment_CPU_lenddate() %></td>
<td><%=eci.getEquipment_CPU_expectreturndate() %></td>
<td><%=eci.getEquipment_CPU_returndate() %></td>
<td><%=eci.getEquipment_CPU_lendhonor() %></td>
<td><%=eci.getEquipment_CPU_remark1() %></td>
<td><%=eci.getEquipment_CPU_remark2() %></td>
<td><%=eci.getEquipment_CPU_remark3() %></td>
<td><a href="updateE_CPUInformation.AdvantechEMS?msgid=<%=eci.getEquipment_CPU_id()%>">修改</a>
</tr>
<%}%>
</tbody>

 

错误代码:

 

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.NullPointerException
    org.apache.jsp.E_005fCPUInformation_jsp._jspService(E_005fCPUInformation_jsp.java:127)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.

 

 

PS:以上是浏览器中显示信息,由于表头都没有显示,所以我估计还是程序与数据库连接出了问题,但是起码我的数据库中还是有数据的。由于我还是不很会debug,所以实在是没办法了。请教各位!谢谢!

  • 写回答

1条回答 默认 最新

  • wanghaolovezlq 2009-07-21 10:33
    关注

    public java.util.List getAllE_CPUInformation(){
    [color=red]java.util.List E_CPUInformationList=new java.util.ArrayList();[/color]
    String sql="SELECT * FROM equipment_CPU";

        try
        {
    
            Connection con=getConn();
            java.sql.PreparedStatement pstm=con.prepareStatement(sql);
            java.sql.ResultSet rs=pstm.executeQuery();         //执行sql语句
    
            while(rs.next())
            {
                E_CPUInformation eci=new E_CPUInformation();
                eci.setEquipment_CPU_id(rs.getString(1));
                eci.setEquipment_CPU_model(rs.getString(2));
                eci.setEquipment_CPU_CoreCode(rs.getString(3));
                eci.setEquipment_CPU_SN(rs.getString(4));
                eci.setEquipment_CPU_socket(rs.getString(5));
                eci.setEquipment_CPU_FSB(rs.getString(6));
                eci.setEquipment_CPU_Level2Cache(rs.getString(7));
                eci.setEquipment_CPU_SPEED(rs.getString(8));
                eci.setEquipment_CPU_version(rs.getString(9));
                eci.setEquipment_CPU_status(rs.getString(10));
                eci.setEquipment_CPU_custodian(rs.getString(11));
                eci.setEquipment_CPU_lender(rs.getString(12));
                eci.setEquipment_CPU_lenddate(rs.getString(13));
                eci.setEquipment_CPU_expectreturndate(rs.getString(14));
                eci.setEquipment_CPU_returndate(rs.getString(15));
                eci.setEquipment_CPU_lendhonor(rs.getString(16));
                eci.setEquipment_CPU_remark1(rs.getString(17));
                eci.setEquipment_CPU_remark2(rs.getString(18));
                eci.setEquipment_CPU_remark3(rs.getString(19));
               [color=red]E_CPUInformationList.add(eci);[/color]
            }
            rs.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
         return E_CPUInformationList;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题