求助,NULL异常
package example_2;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class UserServlet2 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String password=null;
String firstname=null;
String lastname=null;
String age=null;
String gender=null;
ServletContext context=this.getServletContext();
Object obj=context.getAttribute("UserID");
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>CustomerDetails</title></head>");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:test","sa","sa");
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select *from CustomerRegistration where UserID='"+obj.toString()+"'");//空引用,我实在是找不出来原因
boolean flag=rs.next();
if(flag==true){
password=rs.getString(2);
firstname=rs.getString(3);
lastname=rs.getString(4);
gender=rs.getString(5);
age=rs.getString(6);
}else{
out.println("<font color=red size=7>登陆失败</font>");
}
}catch(java.sql.SQLException ex){
out.println("<font color=red size=7>"+ex.toString()+"</font>");
}catch(ClassNotFoundException e){
out.println("类未找到异常"+e.toString());
}
out.println("<body bgcolor=\"#ffffff\">");
out.println("<h1 align=center>欢迎来到 Shop Stop</h1>");
out.println("<table width=80% border=0 align=center>");
out.println("<tr align=center valign=top>");
out.println("<td colspan=2><h1><em><strong>客户详细信息</strong></em></h1></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td width=25%><span><strong>用户ID:</strong></span></td>");
out.println("<td width=75%><span>"+obj.toString()+"</span></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td><span><strong>口令:</strong></span></td>");
out.println("<td><span>"+password+"</span></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td><span><strong>全名:</strong></span></td>");
out.println("<td><span>"+firstname+"</span></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td><span><strong>性别:</strong></span></td>");
out.println("<td><span>"+gender+"</span></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td><span><strong>年龄:</strong></span></td>");
out.println("<td><span>"+age+"岁</span></td>");
out.println("</tr>");
out.println("</table>");
out.println("</body>");
out.println("</html>");
out.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}