<% //获取提交的帐号:
String account=request.getParameter("account");
if(account==null){account="";}
byte b[]=account.getBytes("ISO-8859-1");
account=new String(b);
//获取提交的密码:
String secret=request.getParameter("secret");
if(secret==null){secret="";}
byte c[]=secret.getBytes("ISO-8859-1");
secret=new String(c);
//查询数据库信息,验证身份:
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException event){}
try{
con=DriverManager.getConnection("jdbc:odbc:swx","sa","");
sql=con.createStatement();
String condition="SELECt * FROM staffdl WHERe staffname = "+"'"+account+"'";
rs =sql.executeQuery(condition);
while(rs.next())
{
String n=rs.getString("staffname");
String s=rs.getString("staffmm");
if(account.equals(n)&&secret.equals(s))
{ //将帐号和密码存入session对象,以备在输入界面:inputMessage.jsp中使用:
session.setAttribute("account",account);
session.setAttribute("secret",secret);
//为了防止客户浏览器限制了Cooker的使用,需对连接进行重定向处理:
String s1=response.encodeRedirectURL("staffweb.jsp");
String s2=response.encodeRedirectURL("staffweb.jsp");
//连接到基本信息输入页面:
response.sendRedirect(s1);
}
}
if(!(session.isNew()))
{ out.print("<BR>您输入的帐号或密码不正确"+account+":"+secret);
}
}
catch(SQLException e1) {}
%>
数据库中用户和密码的命名分别是staffname和staffmm,输入框的名字分别是account和secret,要跳转到的页面时staffweb.jsp,数据库中那个表的名字是staffdl
不知道为什么总是跳不过去