package number;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class Servlet1 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 {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String name=request.getParameter("name");
String paw=request.getParameter("paw");
String name1;
String paw1;
boolean fags=false;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载桥驱动
}catch(ClassNotFoundException e){
System.out.println("错误");
}
try{
String url="jdbc:odbc:text";
Connection conn=DriverManager.getConnection(url,"sa","");
Statement s=conn.createStatement();
ResultSet rs=s.executeQuery("select * from table where name='"+name+"'and '"+paw+"'");//从这个地方好象有错
if(rs.next()){
name1=rs.getString(1);
paw1=rs.getString(2);
if(name1!=null&&paw1!=null&&name1==name&&paw1==paw){
fags=true;
}
}
else
{
out.print("登陆失败");
}
}catch(SQLException ex){
out.print("连接失败");
}
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
if(fags){
out.println("<p>欢迎您登陆</p>"+name);
}
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() {
}
}