错误提示:
驱动我也放到lib里面了。
源代码:
package first.second.three;
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.sql.*;
public class loginServlet extends HttpServlet
{
private String url;
private String user;
private String password;
public void init() throws ServletException
{
ServletContext sc=getServletContext();
String driverClass=sc.getInitParameter("driverClass");
url=sc.getInitParameter("url");
user=sc.getInitParameter("user");
password=sc.getInitParameter("password");
try
{
Class.forName(driverClass);
}
catch(ClassNotFoundException ce)
{
throw new ServletException("加载数据库驱动失败!");
}
}
public void doGet (HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
req.setCharacterEncoding("gb2312");
String condition1=req.getParameter("username");
String condition2=req.getParameter("password");
if (condition1==""||condition2=="")
{
resp.sendRedirect("loginFail.html");
return;
}
resp.setContentType("text/html;charset=gb2312");
PrintWriter out=resp.getWriter();
try
{
conn=DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
if(condition1!=""&&condition2!="")
{
rs=stmt.executeQuery("select stu_pwd from stu_info where stu_id=condition1");
if(rs.next())
{
if(rs.getString("stu_pwd")==condition2)
{
resp.sendRedirect("loginSuccess.html");
}
else
{
resp.sendRedirect("loginFail1.html");
}
}
else
{
resp.sendRedirect("loginFail2.html");
}
}
}
catch (SQLException se)
{
se.printStackTrace();
}
}
}
求高手帮解决下