📄 msetting.java
字号:
/*
* 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 java.text.*;
import javax.servlet.http.HttpSession;
import ch06.*;
/**
* 针对个人设置页
* @author ShenYK
* @version 1.0
*/
public class MSetting extends MCommon
{
//得到用户的设置
public boolean getUserSetting( HttpSession mySession )
{
//设置用户信息
Hashtable myValues = (Hashtable)mySession.getAttribute(CommonConst.VIEWID_USER_SETTING);
//获得数据库连接
Connection conn = this.getDBConnection( mySession );
if ( conn == null )
{
return false;
}
Statement stmt = null;
ResultSet rs = null;
try
{
//获得用户名
String sUsername = (String)mySession.getAttribute("username");
stmt = conn.createStatement();
//执行SQL语句
String sQuery = "select * from setting where username='"+sUsername+"'";
rs = stmt.executeQuery( sQuery );
String sCountPerPage = "";
if( rs.next() )
{
sCountPerPage = rs.getString("count_per_page");
}
//放入页面值域
myValues.put( "countPerPage", sCountPerPage );
return true;
}
catch(Exception e)
{
e.printStackTrace();
mySession.setAttribute("errMsg","在数据库中查找用户设置的时候出现错误,请联系技术人员!");
return false;
}
finally
{
try
{
rs.close();
stmt.close();
conn.close();
}catch(Exception ex)
{
}
}
}
//登录用户设置
public boolean registerSetting( HttpSession mySession, String sCountPerPage )
{
//设置用户信息
Hashtable myValues = (Hashtable)mySession.getAttribute(CommonConst.VIEWID_USER_SETTING);
//获得数据库连接
Connection conn = this.getDBConnection( mySession );
if ( conn == null )
{
return false;
}
Statement stmt = null;
ResultSet rs = null;
try
{
//获得用户名
String sUsername = (String)mySession.getAttribute("username");
stmt = conn.createStatement();
String sUpdateSQL = "";
//执行SQL语句
String sQuery = "select * from setting where username='"+sUsername+"'";
rs = stmt.executeQuery( sQuery );
if( rs.next() )
{
sUpdateSQL = "update setting set count_per_page=" + sCountPerPage + " where username='"+sUsername+"'";
}
else
{
sUpdateSQL = "insert into setting set count_per_page=" + sCountPerPage + ", username='"+sUsername+"'";
}
stmt.executeUpdate( sUpdateSQL );
//设置值域
myValues.put( "countPerPage", sCountPerPage );
mySession.setAttribute( "countPerPage", (new Integer(sCountPerPage)).intValue() );
//这个地方比较有趣,登录成功的消息却是放在errmsg的变量中,权作消遣吧
mySession.setAttribute("errMsg","登录成功!");
return true;
}
catch(Exception e)
{
e.printStackTrace();
mySession.setAttribute("errMsg","进行用户设置的时候出现错误,请联系技术人员!");
return false;
}
finally
{
try
{
rs.close();
stmt.close();
conn.close();
}catch(Exception ex)
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -