為什么老是出現空值錯誤呢?

lhx20 2006-09-27 05:23:03
<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean id="db" class="blog.DBConnection" scope="page"></jsp:useBean>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title></title>
<style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
-->
</style></head>

<body>
<h1 align="center">Modify Category </h1>
<hr>
<%
String sid = request.getParameter("id");
int id =java.lang.Integer.parseInt(sid);
String action = request.getParameter("action");
if(action == null)
{
try{
ResultSet rs = db.executeSQL("select * from category where id ="+id);
while(rs.next())
{
String category = rs.getString("category");
%>
<form name="form1" method="post" action="Admin_Modify.jsp?action=Modify">
<table width="50%" border="0" align="center">
<tr>
<td><div align="center">Category Name:</div></td>
<td><div align="center">
<input name="category" type="text" id="category2" value="<%=category%>" size="16">
</div></td>
</tr>
</table>
<table width="50%" border="0" align="center">
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
</form>
<%
}
}
catch(SQLException e)
{
out.print(e.toString());
}
}
else
{
String category = request.getParameter("category");
try{
db.executeSQL("update category set category='"+category+"' where id="+id);
out.print("<script type='text/javascript'>");
out.print("alert('modify sucess');");
out.print("window.location.href='Admin_Category.jsp';");
out.print("</script>");
}
catch(SQLException ex)
{
out.print(ex.toString());
}
}
%>
</body>
</html>


這句話有問題 db.executeSQL("update category set category='"+category+"' where id="+id);

那個id是空值,但是不知道為什么會這樣


錯誤頁
type Exception report

message

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

exception

org.apache.jasper.JasperException: null
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.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:436)
java.lang.Integer.parseInt(Integer.java:518)
org.apache.jsp.Admin.Admin_005fModify_jsp._jspService(Admin_005fModify_jsp.java:71)
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)

...全文
162 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lhx20 2006-09-28
  • 打赏
  • 举报
回复
回 neptune0229(暗长空)

可以獲取得到那個ID,是數字
lhx20 2006-09-28
  • 打赏
  • 举报
回复
chuzhijun(幽恋) ( ) 信誉:100 Blog 2006-9-27 17:34:39 得分: 0



你帖这个获取的页面有啥用,你根本没有获取到ID,关键你的参数如何传的





我的這個ID是從上一個頁面的鏈接得來的http://localhost:8080/myblog/Admin/Admin_Modify.jsp?id=8
Sunny319 2006-09-28
  • 打赏
  • 举报
回复
把int id =java.lang.Integer.parseInt(sid);放到try里面,把这个错误捕获!
Hao粑粑爱生活 2006-09-27
  • 打赏
  • 举报
回复
String sid = request.getParameter("id");
int id =java.lang.Integer.parseInt(sid);
你的SID不是数字,转换的时候出现异常
八喜猫 2006-09-27
  • 打赏
  • 举报
回复
java.lang.NumberFormatException: null

你的ID貌似没有传过来吧?
chuzhijun 2006-09-27
  • 打赏
  • 举报
回复
你帖这个获取的页面有啥用,你根本没有获取到ID,关键你的参数如何传的
neptune0229 2006-09-27
  • 打赏
  • 举报
回复
NumberFormatException
你getParameter("id")的值不是数字

81,091

社区成员

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

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