初学者在线求助:JSP中HTTP Status 500出错(TOMCAT+MYSQL)!

sunpower99 2006-02-12 11:27:31
源码如下:
-----------------------------------------
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>留言本</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="images/web.css" rel="stylesheet" type="text/css">
</head>
<script language="JavaScript">
function openw(url) {
var newwin=window.open(url,"NewWin","toolbar=no,resizable=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,top=220,left=220,width=500,height=330");
// newwin.focus();
return false;
}
function opend(url) {
var newwin=window.open(url,"NewWin","toolbar=no,resizable=yes,location=no,directories=no,status=no,menubar=no,scrollbars=no,top=100,left=50,width=650,height=350");
// newwin.focus();
return false;
}
</script>
<body leftmargin="0" topmargin="1">
<jsp:useBean id="wu" scope="page" class="wu.jdbc" />

<%
Connection con = wu.getConn() ;
Statement stmt = con.createStatement() ;
String sql = "select * from liuyan_temp order by id desc" ;
ResultSet rs = stmt.executeQuery(sql) ;
String pages = request.getParameter("page") ;
int pageInt = 1 ,i=1;
if(pages==null){}else{pageInt = Integer.parseInt(pages);}
while(i<20*(pageInt-1)&&rs.next()){i++ ;}
%>

<table width="775" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td align="center"><img src="images/logo.gif" width="628" height="59" border="1"></td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#16831C">
<tr>
<td colspan="2" bgcolor="#E8FCE2">
<div align="center">
<table width="100%" border="0" cellpadding="1" cellspacing="1">
<tr>
<td><div align="center"><a href="#" onClick="return opend('ly_new.jsp')">添加留言</a></div></td>
<td><div align="center"><a href="http://www.china1024.com">返回主页</a></div></td>
<td><div align="center"><a href="login.jsp">留言管理</a></div></td>
<td><div align="center"><a href="#" onClick="return opend('my.jsp')">我的介绍</a></div></td>
</tr>
</table>
</div>
</td>
</tr>
<%
i=0 ;
String str = "#E8FCE2",str1="" ;
java.util.Random rd = new java.util.Random() ;
while(rs.next()&i<20){
i++ ;
String email = rs.getString("email") ;
String content = rs.getString("content") ;
if(str.equals("#E8FCE2")){
str = "#D1E79E" ;}else{
str = "#E8FCE2" ;
}
%>
<tr>
<td width="23%" bgcolor="<%=str%>">
<div align="center"><%=rs.getString("sj")%></div>
</td>
<td width="77%" bgcolor="<%=str%>">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> <div align="center"><a href="<%=rs.getString("url")%>"><img src="images/HOME.gif" alt="个人主页" width="16" height="16" border="0" align="absmiddle"></a>留言人主页</div></td>
<td> <div align="center"><img src="images/ip.gif" alt="<%=rs.getString("ip")%>" width="13" height="15" align="absmiddle">留言人IP</div></td>
<td> <div align="center"><a href="mailto:<%=email%>"><img src="images/EMAIL.gif" alt="<%=email%>" width="16" height="16" border="0" align="absmiddle"></a>留言人email</div></td>
<td> <div align="center"><img src="images/oicq.gif" alt="<%=rs.getString("qq")%>" width="16" height="16" align="absmiddle">留言人QQ</div></td>
<td><a href="del.jsp?id=<%=rs.getString("id")%>">
<div align="center"><img src="images/dele_1.gif" alt="删除" width="14" height="16" border="0" align="absmiddle">删除留言</div>
</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="<%=str%>"><img src="images/tx/<%=rd.nextInt(30)+1%>.gif" width="100" height="100"><br>
<br>
留言人:<%=rs.getString("xm")%> </td>
<td bgcolor="#FFFFFF">
<%=content%>
</td>
</tr>
<%
}
%>
<tr bgcolor="#F9CDBB">
<td> </td>
<%
sql = "select count(*) from liuyan_temp" ;
rs = stmt.executeQuery(sql) ;
while(rs.next()) i = rs.getInt(1) ;
%>
<td>
<div align="right">总共有留言<%=i%>条/<%=(i+19)/20%>页,这是第<%=pageInt%>页,转到第
<%
for(int j=1;j<(i+40)/20;j++){
%>
<a href="ly.jsp?page=<%=j%>">^<%=j%>^</a>
<%
}
try {
rs.close();
stmt.close();
con.close();
}
catch (Exception ex) {
}
%>

</div>
</td>
</tr>
<tr>
<td bgcolor="<%=str%>"> </td>
<td bgcolor="<%=str%>"> </td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
</table>

</body>
</html>

异常如下:
---------------------------------------------
HTTP Status 500 -

--------------------------------------------------------------------------------

type 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.ly_jsp._jspService(ly_jsp.java:75)
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.

...全文
85 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sunpower99 2006-02-12
空指针?了解
可我数据库字段全都有值啊。
回复
谈祥庆 2006-02-12
都已经提示你错误了,空指针错误,查看代码中每个对象的引用是否有为null的。

另外这样的写法很不好,应该将所有的逻辑代码写在servlet中,JSP中不要出现小脚本。如果需要显示数据,可以使用JSTL标签库
回复
hotsmile 2006-02-12
tomcat 能否正常工作?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

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