?? mlogin.java
字號(hào):
/*
* This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/).
*/
package ch06.module;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
import javax.servlet.http.HttpSession;
import ch06.*;
/**
* 針對(duì)登錄頁面的后臺(tái)處理類
* @author ShenYK
* @version 1.0
*/
public class MLogin extends MCommon
{
public boolean getUserInfo ( HttpSession mySession,
String username,
String password )
{
//設(shè)置用戶信息
Hashtable myValues = (Hashtable)mySession.getAttribute(CommonConst.VIEWID_LOGIN);
myValues.put("username", username);
//獲得數(shù)據(jù)庫連接
Connection conn = this.getDBConnection( mySession );
if ( conn == null )
{
return false;
}
Statement stmt = null;
ResultSet rs = null;
try
{
//檢查數(shù)據(jù)庫中是否已經(jīng)有該用戶了
stmt = conn.createStatement();
//執(zhí)行SQL語句
String sQuery = "select realname from user "
+ "where username='" + username + "' "
+ "and password='" + password +"'";
rs = stmt.executeQuery( sQuery );
if ( rs.next() )
{
mySession.setAttribute("username",username);
mySession.setAttribute("realname",rs.getString(1) );
//獲取用戶設(shè)置
sQuery = "select count_per_page from setting where username='" + username + "'";
rs = stmt.executeQuery( sQuery );
if ( rs.next() )
{
mySession.setAttribute( "countPerPage", new Integer(rs.getInt(1)) );
}
else
{
//默認(rèn)每頁10條
mySession.setAttribute( "countPerPage", new Integer(10) );
}
return true;
}
else
{
mySession.setAttribute("errMsg","用戶名密碼不正確!");
return false;
}
}
catch(Exception e)
{
e.printStackTrace();
mySession.setAttribute("errMsg","出現(xiàn)錯(cuò)誤,請(qǐng)聯(lián)系技術(shù)人員!");
return false;
}
finally
{
try
{
rs.close();
stmt.close();
conn.close();
}catch(Exception ex)
{
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -