急!!求救!!

liulangdegou 2006-03-22 12:01:05
下面的代码是老是发生NullPointerException错误,可是我查了半天没看出来,哪位能帮我看看啊
<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="dao.ConnectToDB" %>
<%!
java.sql.Statement stmt;
Connection conn;
ResultSet rst;
%>
<%
String hid = request.getParameter("dosubmit");
ConnectToDB db = new ConnectToDB();
conn = db.conn;
if(hid != null) {
util.ToChinese tc = new util.ToChinese();
String dID = request.getParameter("deptDraftID");
String cID = request.getParameter("comPlanDraftID");
String taskName = request.getParameter("taskName");
String taskContent = request.getParameter("taskContent");
if(taskContent == null){
taskContent = "";
}
String deptID = request.getParameter("deptID");
String startDate = request.getParameter("startDate");
String completeDate = request.getParameter("completeDate");
String support = (session.getAttribute("data").toString());
String c = "";
if(support != null){
String a = support.substring(1,(support.length()-1));
String[] b = a.split(",");
for(int i = 0; i < b.length; i++){
if(!(b[i].trim()).endsWith("=")){
c = c + b[i].trim()+",";
}
}
}
if(support == null){
support = "";
}
String sql = "update PSS_deptDraftPlan set comPlanDraftID = '"+cID+"',taskName = '"+tc.changeCH(taskName)+"',taskContent = '"+tc.changeCH(taskContent)+"',deptID = '"+deptID+"',startDate = '"+startDate+"',completeDate = '"+completeDate+"',support = '"+c+"' where deptDraftID = '"+dID+"'";
try{
stmt = conn.createStatement();
stmt.executeUpdate(sql);

if(stmt != null){
stmt.close();}
if(conn != null){
conn.close();}
if(session.getAttribute("data") != null){
session.removeAttribute("data");
}
if(session.getAttribute("id") != null){
session.removeAttribute("id");
}
response.sendRedirect("./DeptDeptPlanDraft.jsp");
}catch(Exception e){
e.printStackTrace();
}

}else {

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<LINK rel="stylesheet" href="css\bbs.css" type="text/css">
<html>
<script type="text/javascript" src="js\calendar.js"></script>
<script language="javascript">
var CalendarWebControl = new atCalendarControl();
</script>
<script>
function dopost(){
if(document.form1.taskName.value==""){
alert("任务名称不能为空!");
}else{
form1.submit()
}
}
</script>
<body>
<center>
<FONT face="隶书" color="blue" size="5">部门计划草案详细信息</FONT><br>
<hr size="2" color="green" width="100%"><br>
</center>
<%
String ID = request.getParameter("id");
try{
stmt = conn.createStatement();
rst = stmt.executeQuery("select * from PSS_deptDraftPlan where deptDraftID = '"+ ID +"'");
if(rst.next()){ %>
<center>
<form action="DeptDeptDraftEdit.jsp" method="post" name="form1">
<table align="center" border="1" class="a3" width="100%">
<%
try{
Statement stmt2 = conn.createStatement();
ResultSet rst2 = stmt2.executeQuery("select * from pss_complandraft where isPass = '1' and complandraftid in (select complanID from Pss_Complan where isDone = '2' and isDelete = '2') and isDelete = '2'");
%>
<tr>
<td>部门草案ID</td>
<td><input type="text" value="<%=rst.getString("deptDraftID")%>" readonly="readonly" name="deptDraftID"></td>
</tr>
<tr>
<td>公司计划草案名称</td>
<td><select name="comPlanDraftID">
<%while(rst2.next()){ %>
<option value="<%=rst2.getString("comPlanDraftID")%>"><%=rst2.getString("taskName")%></option>
<%}%>
</select></td>
</tr>
<tr>
<td>任务名称</td>
<td><input type="text" value="<%=rst.getString("taskName")%>" name="taskName"></td>
</tr>
<tr>
<td>部门ID</td>
<td><input type="text" value="<%=rst.getString("deptID")%>" name="deptID" readonly></td>
</tr>
<tr>
<td>任务开始时间</td>
<td><input type="text" value="<%
if(rst.getString("startDate")==null){
out.println("");
}else{
out.println(rst.getString("startDate"));
}%>" name="startDate" readonly onClick="CalendarWebControl.show(this,this.value)"></td>
</tr>
<tr>
<td>要求完成时间</td>
<td><input type="text" value="<%
if(rst.getString("completeDate")==null){
out.println("");
}else{
out.println(rst.getString("completeDate"));
}%>" name="completeDate" readonly onClick="CalendarWebControl.show(this,this.value)"></td>
</tr>
<tr>
<td>工作内容</td>
<td>
<textarea cols="80" rows="8" name="taskContent">
<%if(rst.getString("taskContent")==null){
out.print("");
}else{
out.print(rst.getString("taskContent"));
}%>
</textarea>
</td>
</tr>
<tr>
<td>请求支援</td><td><input type="button" value="请求支援" onclick="location.href('./DeptEditSupport.jsp?id=<%=ID%>')"></td></tr>

<%
if(rst2 != null){
rst2.close();}
if(stmt2 != null){
stmt2.close();}
}catch(Exception e){
e.printStackTrace();
}%>
</table>
<input type="button" value="提 交" onclick="dopost()">
<input type="button" value="返回上一页" onclick="history.back()">
<input type="hidden" name="dosubmit" value="true">
</form>
</center>
<% }else{
out.println("找不到对应的记录!");
}


if(rst != null){
rst.close();}
if(stmt != null){
stmt.close();}
if(conn != null){
conn.close();}
} catch(SQLException e){
e.printStackTrace();
}
%>
</body>
</html>
<%}%>
...全文
82 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
qybao 2006-03-22
太长了,没细看,报错的时候,没有具体指出是哪一行出错吗?
有些地方容易引起这个异常的,你稍微修改试试看,比如
session.getAttribute("data").toString();//万一session.getAttribute("data")为null就处错了
回复
interpb 2006-03-22
把你的tomcat/work目录下找到这个jsp声称的servlet文件

提示空指针 肯定具体到哪一行

找到这行不就行了

不行的话把错误信息全部 ,贴出来
回复
wangx1949 2006-03-22
写代码的时候多用System打印一些数据,这样查错比较方便
回复
zeq258 2006-03-22
jsp 页面目前无法定位到具体的出错地方,

这就要求,一定要有个好的编码习惯,在声明的地方进行初始化。

防止出现 空指针
回复
interpb 2006-03-22
DeptDeptDraftEdit_jsp.java:78 这个文件的78行

因为jsp都是被编译成java文件后运行的
DeptDeptDraftEdit.jsp被编译成 DeptDeptDraftEdit_jsp.java 文件

在你的tomcat安装目录下的work文件夹下面,具体那个子文件夹以你的web工程而定,
自己找一找,然后找到78
行就ok
回复
liulangdegou 2006-03-22
问题我解决了,果然有一行没赋值,不过还是想请楼上的XD教我下如何定位到某一行错误呢?
回复
liulangdegou 2006-03-22
我把所有的报错信息贴上了啊 哪边能看具体是哪一行出错的呢
Exception report

message

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

exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NullPointerException
org.apache.jsp.pss.DeptDeptDraftEdit_jsp._jspService(DeptDeptDraftEdit_jsp.java:78)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


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

回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-03-22 12:01
社区公告
暂无公告