求大神,求指教,为什么会有空指针

qq_24863259 2015-11-04 03:32:12
liuyan.jsp页面
此页面可以运行,可获取值
<% LiuyanOpr po=new LiuyanOpr();
ArrayList<Liuyan> list=po.list();
if(list!=null){
for(Liuyan p:list){
%>
<a href="liuyanxq.jsp?theid=<%=p.getThrid()%>" </a>
<%}} %>


liuyanxq.jsp页面
<%
String strId=request.getParameter("theid");
Liuyan p=null;
if(strId!=null){
int id=Integer.parseInt(strId);

LiuyanOpr po=new LiuyanOpr();
p= po.getLiuyanById(id);
}
%>
<div id="liuyanlist" style="float:left;width:80%;padding-left:100px;height:800px;">
<h2>留言详情<h2>

<div id="tieziliswwt" style="border:1px solid #E8E8E8;font-size:12px;">
<p style="width:100%;color:#A0A0A0" >  发帖人:<span style="color:blue"><%=p.getThrname() %></span><i style="width:250px;float:right;font-size:12px;color:#A0A0A0">发帖日期: <%=p.getThrtime() %></i></p>
<p style="width:80%;padding-left:10%;color:#666;font-size:14px;">标题: <%=p.getThrtitle() %></p>
<p style="width:80%;padding-left:8%;color:#333;font-size:16px;">详情: <%=p.getThrcontant() %></p>
<p style="width:100%;padding-bottom:10px;"><a href="#oranges" style="width:10%;float:right">回复</a></p>
<p><a id="autolink" href="ReplistServlet?flag=relist&rid=<%=strId %>">所有回复</a></p>
</div>

<%

ArrayList<Liuyan> list=(ArrayList<Liuyan>) session.getAttribute("replaydetail");//从Session中取数据
if(list!=null){
for(Liuyan p1:list){

%>

<div id="tiezilisww1t" style="border:1px solid #E8E8E8;font-size:12px;">
<p style="width:100%;color:#A0A0A0" >    回帖人:<span style="color:blue"><%=p1.getRepname() %></span><i style="width:250px;float:right;font-size:12px;color:#A0A0A0">回帖日期:<%=p1.getReptime() %></i></p>
<p style="width:80%;padding-left:10%;color:#666;font-size:14px;">详情:<%=p1.getRepcontant() %></p>
</div>

<%}} %>

servlet内容
String flag=request.getParameter("flag");
if(flag.equals("relist")){

LiuyanOpr po=new LiuyanOpr();

Integer aa=Integer.parseInt(request.getParameter("rid"));
String sql = "select repcontant,repname,reptime,repid,thrid from replay where thrid="+ aa +" order by reptime desc";
ArrayList<Liuyan> list=po.research(sql);

//将 查询到的信息 保存 到 session中
HttpSession session=request.getSession(); //创建Session
session.setAttribute("replaydetail", list);//将数据保存到Session

//跳转页面
response.sendRedirect("liuyanxq.jsp");//页面重定向
}

数据库操作类

public ArrayList<Liuyan> research(String sql){ //获取查询

ArrayList<Liuyan> list = new ArrayList<Liuyan>();
try {
psmt = con.prepareStatement(sql);
ResultSet rs = psmt.executeQuery();
while(rs.next()){
Liuyan p = new Liuyan();
p.setRepid(rs.getInt("repid"));
p.setThrid(rs.getInt("thrid"));
p.setRepname(rs.getString("repname"));
p.setReptime(rs.getString("reptime"));
p.setRepcontant(rs.getString("repcontant"));
list.add(p);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}




报错

2015-11-4 15:11:47 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.liuyanxq_jsp._jspService(liuyanxq_jsp.java:180)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.biyesheji.srevlet.EncodingFilter.doFilter(EncodingFilter.java:32)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:619)


页面报错
type Exception report

message

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /liuyanxq.jsp at line 121

118: <h2><h2>
119:
120: <div id="tieziliswwt" style="border:1px solid #E8E8E8;font-size:12px;">
121: <p style="width:100%;color:#A0A0A0" >  <span style="color:blue"><%=p.getThrname() %></span><i style="width:250px;float:right;font-size:12px;color:#A0A0A0"><%=p.getThrtime() %></i></p>
122: <p style="width:80%;padding-left:10%;color:#666;font-size:14px;"><%=p.getThrtitle() %></p>
123: <p style="width:80%;padding-left:8%;color:#333;font-size:16px;"><%=p.getThrcontant() %></p>
124: <p style="width:100%;padding-bottom:10px;"><a href="#oranges" style="width:10%;float:right"></a></p>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:426)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.biyesheji.srevlet.EncodingFilter.doFilter(EncodingFilter.java:32)
root cause

java.lang.NullPointerException
org.apache.jsp.liuyanxq_jsp._jspService(liuyanxq_jsp.java:180)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.biyesheji.srevlet.EncodingFilter.doFilter(EncodingFilter.java:32)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.

Apache Tomcat/6.0.10
...全文
72 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
街头小贩 2015-11-08
  • 打赏
  • 举报
回复
提示的不够清楚明了吗?

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧