登录类型判断后提交给不同的表格验证的问题
这段代码的问题是:只有当提交类型为学生的时候登录正常。其他的两个登录类型都不能验证成功。而是返回到了index.jsp最初的登录名和密码填写的页子。。。 请高手指点。。。
代码如下:
<%@ page language="java" errorPage="error.jsp" pageEncoding="gb2312" import="java.sql.*,dBc.DBC" %>
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>login</title>
</head>
<body bgcolor="#FFFFFF">
<jsp:useBean id="userbean" scope="page" class="dBc.DBC" />
<%
int k;
String sql="";
String id=userbean.toZh(request.getParameter("name"));
String psw=userbean.toZh(request.getParameter("psw"));
String type=request.getParameter("select");
if(type.equals("students")){
sql="select * from wlxy_students where id="+"\'"+id+"\' and psw="+"\'"+psw+"\' ";
}
else if(type.equals("teachers")){
sql="select * from wlxy_teachers where id="+"\'"+id+"\' and psw="+"\'"+psw+"\' ";
}
else if(type.equals("Admin")){
sql="select * from wlxy_Admin where id="+"\'"+id+"\' and psw="+"\'"+psw+"\' ";
}
else{
out.print("<script>alert('用户登录类型出错'); javascript:history.go(-1);</script> ");
}
//sql="select * from wlxy_students where id="+"\'"+id+"\' and psw="+"\'"+psw+"\' ";
k=userbean.select(sql);
if(k>0){
//application.setAttribute();
out.println(sql);
response.sendRedirect("index1.jsp");
}else{
response.sendRedirect("index.jsp");
}
userbean.close();
%>
</body>
</html>