<%@ page language="java" import="java.util.*" contentType="text/html;charset=GBK"%> <%@ page import 50
<%@pagelanguage="java"import="java.util.*"contentType="text/html;charset=GBK"%><%@pag...
<%@ page language="java" import="java.util.*" contentType="text/html;charset=GBK"%>
<%@ page import ="java.text.*" %>
<%@ page import ="vo.*" %>
<%@ page import ="vote.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>显示</title>
</head>
<body bgcolor="#F0F0F0">
<%Votetitle t=(Votetitle)request.getAttribute("t");
Collection d=t.getVoteitem();
Date startTime=t.getStartime();
Date now=new Date();
最后4行有错,
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 /ShowVote.jsp at line 23
20:
21:
22: <%Votetitle t=(Votetitle)request.getAttribute("t");
23: Collection d=t.getVoteitem();
24: Date startTime=t.getStartime();
25: Date now=new Date();
26:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
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)
root cause
java.lang.NullPointerException
org.apache.jsp.ShowVote_jsp._jspService(ShowVote_jsp.java:83)
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:393)
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)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
求好心人帮忙。
先谢谢大家,t 我赋值了(request.setAttribute("t",t),自己找不到错,郁闷。
public class showvote extends HttpServlet {
private static final long serialVersionUID = 1L;
public showvote() {
super();}
public void destroy() {
super.destroy(); }
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("text/html;charset=GBK");
在这里赋值的
String id=request.getParameter("id");
String page=request.getParameter("page");
VoteDao mgr=new VoteDao();
Votetitle t=mgr.getVote(Integer.parseInt(id));
request.setAttribute("t", t);
try{
request.getRequestDispatcher(page).forward(request, response);
}catch(Throwable t1){
getServletContext().log(t1.getMessage());
}
}
} 展开
<%@ page import ="java.text.*" %>
<%@ page import ="vo.*" %>
<%@ page import ="vote.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>显示</title>
</head>
<body bgcolor="#F0F0F0">
<%Votetitle t=(Votetitle)request.getAttribute("t");
Collection d=t.getVoteitem();
Date startTime=t.getStartime();
Date now=new Date();
最后4行有错,
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 /ShowVote.jsp at line 23
20:
21:
22: <%Votetitle t=(Votetitle)request.getAttribute("t");
23: Collection d=t.getVoteitem();
24: Date startTime=t.getStartime();
25: Date now=new Date();
26:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
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)
root cause
java.lang.NullPointerException
org.apache.jsp.ShowVote_jsp._jspService(ShowVote_jsp.java:83)
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:393)
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)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
求好心人帮忙。
先谢谢大家,t 我赋值了(request.setAttribute("t",t),自己找不到错,郁闷。
public class showvote extends HttpServlet {
private static final long serialVersionUID = 1L;
public showvote() {
super();}
public void destroy() {
super.destroy(); }
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("text/html;charset=GBK");
在这里赋值的
String id=request.getParameter("id");
String page=request.getParameter("page");
VoteDao mgr=new VoteDao();
Votetitle t=mgr.getVote(Integer.parseInt(id));
request.setAttribute("t", t);
try{
request.getRequestDispatcher(page).forward(request, response);
}catch(Throwable t1){
getServletContext().log(t1.getMessage());
}
}
} 展开
4个回答
展开全部
我也曾碰到过一模一样的错:
原因是<c:when test="$"> 这句话,这个没有任何意义.
实际项目中是不会出现的,不用担心:一般是一个变量与一个常量对比,或者两个变量对比,不会出现常量对比的
原因是<c:when test="$"> 这句话,这个没有任何意义.
实际项目中是不会出现的,不用担心:一般是一个变量与一个常量对比,或者两个变量对比,不会出现常量对比的
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
空指针 异常 原因是 因为 t 没有值 是null 当你调用 t.getxxx方法的时候 就会报错 你检查一下 赋值的时候 有没有值!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
空指针吗 是不是服务端 没有设置属性 request.setAttribute("t")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Votetitle t=mgr.getVote(Integer.parseInt(id));这句话应该是一个查询过程吧?如果查询结果是空的话,request.setAttribute("t", t);这句话其实仅仅是设置了一个空值,所以你在页面中调用
Votetitle t=(Votetitle)request.getAttribute("t");得到的t也是一个空值,然后你调用t的getStartime();就引起异常了。
你这么写
Votetitle t=mgr.getVote(Integer.parseInt(id));
if(t!=null) {
request.setAttribute("t", t);
}else {
request.setAttribute("t",new Votetitle());
}
页面就应该不会有异常了。我觉得可能原因是你的数据库中没有这个数据。
Votetitle t=(Votetitle)request.getAttribute("t");得到的t也是一个空值,然后你调用t的getStartime();就引起异常了。
你这么写
Votetitle t=mgr.getVote(Integer.parseInt(id));
if(t!=null) {
request.setAttribute("t", t);
}else {
request.setAttribute("t",new Votetitle());
}
页面就应该不会有异常了。我觉得可能原因是你的数据库中没有这个数据。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询