大家帮忙看下
空指针异常问题:下面这段代码当选择设备时,能正常显示结果,但选择教室时,结果也能显示出来,却多出一句异常报告,请大家指点!
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<html> <font>
<head>
<title>普通用户 </title>
<style>
body {
background-color: #FFFFCC;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
div {background-color:#CCFFCC;}
.f1 {border:solid;border-width:1px;}
.t1 {background-color:#CCFFFF;width:100%;}
.t2 {border-right:solid;color:black;border-width:3px;}
A {text-decoration:none;}
.STYLE3 {
font-size: medium;
font-family: "华文行楷";
}
</style>
</head>
<%
Object o = session.getAttribute("uname");
if(o==null)
{
response.sendRedirect("login.jsp");
}
%>
<body>
<div align="center" class="t1">
<TABLE>
<TR>
<TD class="t3"> <h1>实验室设备管理系统 </h1> </TD>
</TR>
</TABLE>
</div>
<div align="center" class="f1">
<TABLE>
<TR>
<TD class="t2"> <A href="sel_dev_u.jsp">设备查询/预订 </A> </TD>
<TD class="t2"> <A href="sel_lab_u.jsp">教室查询/预订 </A> </TD>
<td class="t2"> <A href="use_message.jsp">使用信息 </A> </td>
<td class="t2"> <A href="book_record.jsp?id=u">预订处理 </A> </td>
<td class="t2"> <A href="chpwd.jsp?id=u">修改密码 </A> </td>
<td class="t2"> <A href="exit.jsp">注销[退出] </A> </td>
</TR>
</TABLE>
</div>
<%
String ddate=new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());%>
当前日期: <%=ddate%>
<hr color="yellow">
<form action="use_message.jsp" method="post">
<table>
<tr>
<td>用户名: <input type="text" name="name"/> </td>
<td> <span>使用类别: </span>
<select name="sel" selected="==设备==">
<option value="设备">==设备== </option>
<option value="教室">==教室== </option>
</select>
</td>
<td> <input type="submit" name="submit" value="查询"/> </td>
</tr>
</table>
</form>
<%
String name=request.getParameter("name");
String sel=request.getParameter("sel");
if((name==null)&&(sel==null))
{
}
else
{
name=new String(name.getBytes("ISO8859-1"));
sel=new String(sel.getBytes("ISO8859-1"));
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/device","root","123456");
Statement stmt=conn.createStatement();
String sql="";
if("设备".equals(sel))
{
%>
<TABLE>
<TR>
<TD>设备号 </TD>
<TD>类别 </TD>
<TD>教室编号 </TD>
<TD>用户 </TD>
<TD>借出时间 </TD>
<TD>归还时间 </TD>
</TR>
<%
sql="select * from lend where lname='"+name+"'";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
{
rs.previous();
while(rs.next())
{
String devno=new String (rs.getString("devno").getBytes("GB2312"));
String devclass=new String (rs.getString("devclass").getBytes("GB2312"));
String labno=new String (rs.getString("labno").getBytes("GB2312"));
String lname=new String (rs.getString("lname").getBytes("GB2312"));
String ltime=new String (rs.getString("ltime").getBytes("GB2312"));
String etime=new String (rs.getString("etime").getBytes("GB2312"));%>