打了补丁还是没用,这段错误又是怎么一回事? type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerException com.softeem.studentunion.dao.LoginDao.validate(LoginDao.java:26) com.softeem.studentunion.servlet.LoginServlet.process(LoginServlet.java:50) com.softeem.studentunion.servlet.LoginServlet.doPost(LoginServlet.java:41) javax.servlet.http.HttpServlet.service(HttpServlet.java:709) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerException
com.softeem.studentunion.dao.LoginDao.validate(LoginDao.java:26)
com.softeem.studentunion.servlet.LoginServlet.process(LoginServlet.java:50)
com.softeem.studentunion.servlet.LoginServlet.doPost(LoginServlet.java:41)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
package com.softeem.studentunion.dao;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;public class LoginDao {
private Connection conn;
private PreparedStatement ps = null;
private ResultSet rs = null;
private final static String SQL_FIND = "select password from login where username=?"; public LoginDao(Connection conn) {
super();
this.conn = conn;
}
public boolean validate(String username,String password){
boolean flag = false;
try {
ps = conn.prepareStatement(SQL_FIND);
ps.setString(1, username);
rs = ps.executeQuery();
while(rs.next()){
if(rs.getString(1).equals(password)){
flag = true;
break;
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(conn != null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return flag;
}}
import java.sql.Connection;import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.softeem.studentunion.dao.DataSourceFactory;
import com.softeem.studentunion.dao.LoginDao;/**
* Servlet implementation class for Servlet: LoginServlet
*
*/
public class LoginServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
public LoginServlet() {
super();
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
process(request,response);
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
process(request,response);
}
protected void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String forward = null;
String username = request.getParameter("username");
String password = request.getParameter("password");
Connection conn = DataSourceFactory.getConnection();
LoginDao dao = new LoginDao(conn);
if(dao.validate(username, password)){
forward = "MemberListServlet";
}else{
forward = "failure.jsp";
}
RequestDispatcher rd = request.getRequestDispatcher(forward);
rd.forward(request, response);
}
}
1:检查 Connection conn = DataSourceFactory.getConnection();中conn是否成功
2:查看 String username = request.getParameter("username");String password = request.getParameter("password");中 username和password是否已经获取
3:检查 ResultSet rs
第三步可能不需要检查了,我分析是根本就没拿到Connection,看看你的DataSourceFactory吧
如果跳转有问题,就看看路径写对了吗
别用ms的driver
推荐使用jTDS