我有一个JSP页面中有7个FORM (里面有学号 姓名 年龄等) 想不管输入哪个都可以从数据库中查询
但是Servlet编译成功 可是JSP页面运行时显示
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
people.query.doPost(query.java:51)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
请问这是什么问题啊?是不是SQL语句写的不对???
package people;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class query extends HttpServlet{
private static final String CONTENT_TYPE="text/html;charset=GB2312";
public void init() throws ServletException{
super.init();}
//执行HTTP POST请求
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
PrintWriter out=response.getWriter();
response.setContentType(CONTENT_TYPE);
out.print("<html>");
out.print("<body>");
//获得客户端用post方法传来的数据
String number=request.getParameter("number");
System.out.println(number);
String name=request.getParameter("name");
System.out.println(name);
String sex=request.getParameter("sex");
System.out.println(sex);
String nianlin=request.getParameter("nianlin");
System.out.println(nianlin);
String jiguan=request.getParameter("jiguan");
System.out.println(jiguan);
String yuanxi=request.getParameter("yuanxi");
System.out.println(yuanxi);
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");}
catch(ClassNotFoundException e){e.printStackTrace();}
try{
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=university","sa","");
String sql="select * from student where number like "+"'"+number+"'";
rs=stmt.executeQuery(sql);
out.print("<table border>");
out.print("<tr>");
out.print("<th width=100>"+"学号");
out.print("<th width=100>"+"姓名");
out.print("<th width=30>"+"性别");
out.print("<th width=50>"+"年龄");
out.print("<th width=100>"+"籍贯");
out.print("<th width=100>"+"院系");
out.print("</tr>");
//循环显示结果
while(rs.next())
{
out.print("<tr>");
number=rs.getString(1);
out.print("<td>"+number+"</td>");
name=rs.getString(2);
out.print("<td>"+name+"</td>");
sex=rs.getString(3);
out.print("<td>"+sex+"</td>");
nianlin=rs.getString(4);
out.print("<td>"+nianlin+"</td>");
jiguan=rs.getString(5);
out.print("<td>"+jiguan+"</td>");
yuanxi=rs.getString(6);
out.print("<td>"+yuanxi+"</td>");
out.print("</tr>");
}
out.print("</table>");
conn.close();
}catch(SQLException e){}
out.print("</html>");
out.print("</body>");
}
public void destroy(){
}
}