Vector menu_first = new Vector(); // 通过拥有角色不重复找出一级菜单,并存入session中 String url_3 = "select distinct power.modle_first_id,modle_first.name,modle_first.inorder from power inner join modle_first " + " on modle_first.modle_first_id = power.modle_first_id where role_id in (" + role_ids + ") and power.status=1 Order By modle_first.inorder,power.modle_first_id";
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.sql.*;
import java.lang.Integer;
import java.lang.Exception;
import java.util.Vector;import com.vitech.hosting.*;
import com.vitech.util.*;public class loginCheck extends HttpServlet {
public void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html; charset=GBK");
HttpSession session = req.getSession(true);
PrintWriter pw = res.getWriter();
String username = req.getParameter("username");
String password = req.getParameter("password");
String dbDriver = hostingProperties.getProperty("dbDriver");
String dbUrl = hostingProperties.getProperty("dbUrl");
String dbUser = hostingProperties.getProperty("dbUser");
String dbPasswd = hostingProperties.getProperty("dbPasswd");
int login_count;
String sysuser_id,company_id,isseller;
ResultSet rs = null;
try {
hostingSQLConnect myConn = new hostingSQLConnect(dbDriver, dbUrl, dbUser, dbPasswd);
Connection conn = myConn.getConnection(); Statement stmt = conn.createStatement();
String url_1 = "select sysuser_id,login_count,company_id,isseller from sysuser where username ='" + strProc.prep4DB(username) + "' and password ='" + strProc.prep4DB(password) + "' and status=1";
rs = stmt.executeQuery(url_1);
if( rs.next() )
{
sysuser_id = rs.getString(1);
login_count = rs.getInt(2);
company_id = rs.getString(3);
isseller = rs.getString(4);
if (isseller == null) isseller = "0";
// 纪录此用户登录次数
String url_2 = "update sysuser set login_count="+ (login_count + 1) + " where sysuser_id=" + sysuser_id;
stmt.executeUpdate(url_2);
}
// 如果用户名/密码错误,跳出alert窗口,返回修改
else
{
String errorMsg = "对不起,用户名/密码错误!";
String outMsg = "<HTML>" +
"<head>" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">" +
"<!-- The Servlet expression tags interpolate script variables into the HTML -->" +
"<title>error</title>" +
"</head>" +
"<body bgcolor=#ffffff>" +
"<script language=\"javascript\">" +
"alert(\"" + errorMsg + "\");" +
"window.history.back(-1);" +
"</script>" +
"</body>";
pw.println(outMsg);
pw.close(); return;
}
session.setAttribute("sessionid", session.getId());
// 将用户ID存入session中
session.setAttribute("sysuser_id",sysuser_id);
// 将公司ID存入seeesion中
session.setAttribute("company_id",company_id);
// 找出用户所具备的角色
session.setAttribute("isseller",isseller); String url_2 = "select role_id from limit where status=1 and sysuser_id=" + session.getAttribute("sysuser_id");
rs = stmt.executeQuery(url_2);
String role_ids = "";
while(rs.next())
{
role_ids += rs.getString(1) + ",";
}
if (role_ids.length() > 0) role_ids = role_ids.substring(0,role_ids.length() - 1);
Vector menu_first = new Vector(); // 通过拥有角色不重复找出一级菜单,并存入session中
String url_3 = "select distinct power.modle_first_id,modle_first.name,modle_first.inorder from power inner join modle_first " +
" on modle_first.modle_first_id = power.modle_first_id where role_id in (" + role_ids + ") and power.status=1 Order By modle_first.inorder,power.modle_first_id";
rs = stmt.executeQuery(url_3);
while(rs.next())
{
Vector menu_first_item = new Vector();
menu_first_item.add(rs.getString(1));
menu_first_item.add(strProc.localEnc(rs.getString(2)));
menu_first.add(menu_first_item);
}
session.setAttribute("role_ids", role_ids);
session.setAttribute("menu_first", menu_first); conn.close(); // 显示一级菜单
res.sendRedirect("/MainMenu.jsp");
} catch (Exception e) {
e.printStackTrace();
throw new ServletException(e.toString());
}
pw.close();
return;
}
}说是throw new ServletException(e.toString()); 行出错。