当前位置: 技术问答>java相关
遇到问题了!!!!Need帮助!
来源: 互联网 发布时间:2015-06-08
本文导语: 0) MM_LoginAction += "?" + request.getQueryString(); String MM_valUsername=request.getParameter("txtID"); if (MM_valUsername != null) { String MM_fldUserAuthorization=""; String MM_redirectLoginSuccess="loginok.jsp"; String MM_redirectLoginFailed="loginfai...
0) MM_LoginAction += "?" + request.getQueryString();
String MM_valUsername=request.getParameter("txtID");
if (MM_valUsername != null) {
String MM_fldUserAuthorization="";
String MM_redirectLoginSuccess="loginok.jsp";
String MM_redirectLoginFailed="loginfailure.jsp";
String MM_redirectLogin=MM_redirectLoginFailed;
Driver MM_driverUser = (Driver)Class.forName(MM_user_DRIVER).newInstance();
Connection MM_connUser = DriverManager.getConnection(MM_user_STRING,MM_user_USERNAME,MM_user_PASSWORD);
********************************************************
String MM_pSQL = "SELECT UserID,Password,UserRight";
********************************************************
if (!MM_fldUserAuthorization.equals("")) MM_pSQL += "," + MM_fldUserAuthorization;
MM_pSQL += " FROM dbo.UserDetail WHERE UserID='" + MM_valUsername + "' AND Password='" + request.getParameter("txtPSW") + "'";
PreparedStatement MM_statementUser = MM_connUser.prepareStatement(MM_pSQL);
ResultSet MM_rsUser = MM_statementUser.executeQuery();
//读入用户权限
String MM_valUserRight = MM_rsUser.getObject("UserRight").toString();
session.putValue("MM_UserRight",MM_valUserRight);
boolean MM_rsUser_isNotEmpty = MM_rsUser.next();
if (MM_rsUser_isNotEmpty) {
// username and password match - this is a valid user
session.putValue("MM_Username", MM_valUsername);
if (!MM_fldUserAuthorization.equals("")) {
session.putValue("MM_UserAuthorization", MM_rsUser.getString(MM_fldUserAuthorization).trim());
} else {
session.putValue("MM_UserAuthorization", "");
}
if ((request.getParameter("accessdenied") != null) && false) {
MM_redirectLoginSuccess = request.getParameter("accessdenied");
}
MM_redirectLogin=MM_redirectLoginSuccess;
}
MM_rsUser.close();
MM_connUser.close();
response.sendRedirect(response.encodeRedirectURL(/tech-qa-java/MM_redirectLogin/index.html));
}
%>
这是我用Dreamweaver UltraDev做的一个登录页面中的部分语句(基本上都是用UltraDev自带的功能做的)。在星号中间的那句话如果不加UserRight是可以通过执行的,但是加了一个UserRight就报 Invalid curor state的错。我想知道为什么?而且我需要UserRight这个变量用session传递。
应该怎么办?谢谢!
|
String MM_valUserRight = MM_rsUser.getObject("UserRight").toString();
session.putValue("MM_UserRight",MM_valUserRight);
boolean MM_rsUser_isNotEmpty = MM_rsUser.next();
if (MM_rsUser_isNotEmpty) {
// username and password match - this is a valid user
session.putValue("MM_Username", MM_valUsername);
if (!MM_fldUserAuthorization.equals("")) {
session.putValue("MM_UserAuthorization", MM_rsUser.getString(MM_fldUserAuthorization).trim());
} else {
session.putValue("MM_UserAuthorization", "");
}
if ((request.getParameter("accessdenied") != null) && false) {
MM_redirectLoginSuccess = request.getParameter("accessdenied");
}
MM_redirectLogin=MM_redirectLoginSuccess;
}
MM_rsUser.close();
MM_connUser.close();
这些改成
if(MM_rsUser.next()){
String MM_valUserRight = MM_rsUser.getObject("UserRight").toString();
session.putValue("MM_UserRight",MM_valUserRight);
// username and password match - this is a valid user
session.putValue("MM_Username", MM_valUsername);
if (!MM_fldUserAuthorization.equals("")) {
session.putValue("MM_UserAuthorization", MM_rsUser.getString(MM_fldUserAuthorization).trim());
} else {
session.putValue("MM_UserAuthorization", "");
}
if ((request.getParameter("accessdenied") != null) && false) {
MM_redirectLoginSuccess = request.getParameter("accessdenied");
}
MM_redirectLogin=MM_redirectLoginSuccess;
}
MM_rsUser.close();
MM_connUser.close();
这回试一下,因为最初的状态集的游标在第一条记录的前面,所以
MM_rsUser.getObject("UserRight")是无效的