- 浏览: 1121048 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (1055)
- quartz定时任务 (1)
- json (9)
- 接口 (1)
- http (1)
- sccket (2)
- xmlbean (1)
- webservice (1)
- flex (1)
- sitemesh (2)
- json组装 (2)
- 存储过程 (6)
- ajax后台返回前台上下问 (3)
- flect反射机制 (1)
- 页面列表 (1)
- oracal结果集合并 (1)
- lucene (1)
- 读取配置文件工具 (1)
- 框架整合 (1)
- jms (3)
- 断点续传 (1)
- 页面之间的传值 (1)
- jpa (6)
- sql (8)
- jsp跳转 (1)
- jsp (6)
- jquery (2)
- ui (1)
- js与jsp之间的值的交互应用 (1)
- js空值判断 (1)
- Ajax (9)
- web-inf 编译目录 (1)
- 多线程 (9)
- 资料 (0)
- oracal (4)
- 多线程webservice (1)
- ztree (1)
- 加载与内容的变化 (1)
- 页面的公用变量 (1)
- web-inf目录结构 (1)
- 登陆系列 (1)
- jass应用于webservice认证 (2)
- 路径问题 (1)
- list合并 (1)
- list map中的value获取 (2)
- 标签tag (4)
- 方法 (1)
- 树形数据及其渲染 (1)
- require js 回调 (1)
- tab 页面切换 (2)
- 计时获取验证码 (1)
- 模式 (6)
- easyui (3)
- dialog (2)
- 乱码问题 (1)
- spring (29)
- sqlserver (1)
- iis,netframework (0)
- iis (1)
- netframework (1)
- 处理乱码问题 (1)
- struts-ajax (0)
- ,理论,了;,; (0)
- 排错方法 (1)
- hibernate (1)
- 二级缓存 (1)
- portal (1)
- date类型 (0)
- jvm out of memery StackOverflowError (1)
- echart数据填充 (0)
- echart (1)
- jmv (1)
- 学习 (0)
- java基础 (1)
- oracle性能优化 (1)
- 数据库三范式 (1)
- easy UI (1)
- oracle11g (1)
- form (3)
- servlet (2)
- spring mvc (1)
- htm5 (0)
- ibatise (1)
- 序列化 (1)
- tomcat双认证 (1)
- maven Lib (1)
- tomcat eclipse (2)
- ehcache (1)
- http 代替 ajax (2)
- rest (6)
- script脚本占位模板 (1)
- strust 标签 el表达式 (1)
- js bo (1)
- 公司资料 (0)
- js return (1)
- spring 第三方插件的工具类 (1)
- linux (10)
- linux 克隆 (1)
- linux xshell连接 (1)
- yum expect (1)
- linux 应用命令 (1)
- yum 缓存rmp包 (1)
- yum 本地库离线安装 (2)
- yum错误 (1)
- jsp页面用定时调用 (1)
- ajax setup (2)
- Exception,RuntimeException (1)
- 对话框 dialog (1)
- maven (17)
- PropertyPlaceholderConfigurer properties文件 (1)
- 错误集 (1)
- mybatise (0)
- 拦截器filter (1)
- http get post 区别 (1)
- rest 客户端两种返回的数据处理方式 (1)
- listener (2)
- maven工程 (1)
- ContainerResponseFilter (1)
- ajax action 打印任意实体类jsp (1)
- yum svn mvn (1)
- 分页 (1)
- angularjs (1)
- memcached (1)
- git (12)
- yyyyyyyy (0)
- oracal安装 (4)
- jaxwswebservice (1)
- spring bean (1)
- 排方法 (0)
- java 生成pdf (2)
- 创建目录 (1)
- 下载与生产pdf文件 (1)
- base64 (2)
- 配置文件 (2)
- blob (1)
- pdf (1)
- yum linux 安装Oracle (1)
- excl 插入数据库 (1)
- 搭建框架 (1)
- .classpath和jdk jre (1)
- mybatise 配置文件通配 (1)
- 用Maven插件生成Mybatis代码 (2)
- springmvc值的传递 (1)
- js jsp html (1)
- ajax跨域 (1)
- javamail (0)
- 提交复杂格式json数据 (1)
- get中文乱码/post (1)
- 弹出框,承载弹出链接----页面,显示大图 (1)
- @RequestBody list bean (1)
- 隐藏域 (1)
- 多页保存 (1)
- form 校验 (1)
- 注册,上传图片 (1)
- 登录验证 (1)
- 全局的异常处理 (0)
- 异常捕获,显示在页面 (0)
- mybatise事物配置 (1)
- maven compile (1)
- 时间格式 (1)
- js 跳转页面 (1)
- pringsecurity 角色授资源要重启服务 (0)
- Retrofi restfull (1)
- session过期推出,直接点击退出,退出 (0)
- 参数放于requestbody (1)
- maven本地仓库jar包 (1)
- 编译环境出错jdk1.6 1,7 (1)
- jsonarray ---json数组格式 (1)
- java后台文件上传,接受的2种方式 (0)
- 生成保存图片 (1)
- 权限mysql数据库Md5加密sql (1)
- mysql一对多关联查询 (1)
- mysql批量更新 (0)
- oracle in exists 区别 (1)
- https (1)
- linux发布脚本 (1)
- dubbo zookeepr (1)
- request.getParameter() (1)
- request.setAttribute() (1)
- @RequestMapping @ResponseBody (1)
- @RequestMapping @responsebody src控件 后台如何写入src值 (1)
- dwz (8)
- lib jar maven (1)
- web服务访问名称 (1)
- mvc返回内容设置,拦截 (1)
- @ResponseBody 返回json处理 (1)
- 视图,函数,存储过程 (1)
- <context:annotation-config/> (1)
- <context:component-scan/> (1)
- xml路劲通配 (2)
- 杂项 (1)
- dubbo (34)
- redis (25)
- mybatis (34)
- springmvc (15)
- js (7)
- sprinvmvc (1)
- 设计理念 (1)
- 工程 (1)
- 其他 (149)
- 导出,下载 (1)
- session (4)
- token (1)
- Exception处理 (2)
- 注解 (2)
- 框架 (3)
- shrio (1)
- login (1)
- 项目结构设计 (1)
- mybatis两种关联查询 (1)
- mybaits (2)
- 迭代模式 (1)
- oralce树形数据结构构建 (2)
- 树形结构的jsp展现 (1)
- filter intecept(Struts) (1)
- 树形结构数据的提交 (1)
- @RequestBody @RequestParam (1)
- div (1)
- equals重写 (1)
- 程序设计 (1)
- f多层for循环跳出 (1)
- 看源码 (0)
- 权限系统普遍通性 (1)
- 设计程序 (1)
- 动态拼接元素样式问题 (1)
- sql迭代 (1)
- debug断点 (1)
- spring mvc 扫描注解(ioc (1)
- di) (1)
- jdk (2)
- cglib (1)
- mybatis 多层括号(超过三层)解析不了 (1)
- tiles (2)
- cacheManager缓存的切换 (1)
- jsp,xml中el表达式等占位符中的数据操作 (1)
- jpa 及spring data jpa开发 (1)
- compareTo equals toString (1)
- 子页面用父页面js (1)
- jsp相对路径自加问题 (1)
- bean之间的相互拷贝 (1)
- DECODE (2)
- 泛型 (2)
- NVL (1)
- jsp jstl函数 用标签声明页面变量,供jstl使用,时间格式问题 (1)
- form表单切换action值 (1)
- response.getWriter().write()功能优于springMvc的返回 (1)
- 快速复制构建项目 (1)
- activeMq (15)
- cache (2)
- sql获取序列号 (1)
- 上传 (2)
- tfs (1)
- jsp标签 (2)
- qita (1)
- 触发器 (1)
- Exception (1)
- mybais (1)
- 标签 (1)
- connect by (1)
- for ... in (1)
- map转化为list (1)
- 树形结构list构建(树形实体) (1)
- 左侧菜单的设计 (1)
- response.getWriter().write() (1)
- eclipse打断点之后断无效 (1)
- 直接访问/web-inf/下的页面 (1)
- clob (1)
- freemark (1)
- 框架的设计 (1)
- get方式处理乱码 (1)
- Request的getParameter和getAttribute方法的区别 (1)
- cas (9)
- 时间格式问题 (1)
- ResponseUtil.writeToResponse (1)
- 树形数据的反选 (1)
- spring data jpa (1)
- jsp异常提示 (1)
- jquery js (1)
- eclipse (1)
- 乱码 (1)
- Json OBJETC (1)
- PROCEDURE (1)
- pl/sql oracle (1)
- 设计 (1)
- el表达式 (3)
- iframe (1)
- map (1)
- jsp中调用Java (1)
- response.getWriter().write() ajax (1)
- mybatis xml 传入参数 (0)
- response与request在返回时作用区别 (1)
- spring cache (1)
- 模型驱动 (1)
- 关于mybatis传空值的处理 (1)
- 日志配置 (1)
- mapper (1)
- mapper mybatis (1)
- mapper mybatis-spring spring-data-jpa (1)
- js插件 (1)
- spring-data-jpa (2)
- 字节流转化过程 (1)
- 数据库 (11)
- jsp页面 (1)
- 局域网络访问问题 (1)
- plsql (2)
- response (1)
- plsq (1)
- Proxool (1)
- cas security (1)
- 系统配置化 (1)
- 集群 (4)
- springboot (24)
- 设计模式 (5)
- 通知 (1)
- 架构 (48)
- zookeeper (5)
- mvc框架 (1)
- 事物隔离策略 (1)
- jvm (8)
- 调研 (1)
- Java工具类 (1)
- 并发容器 (3)
- 多线程管理器 (4)
- 简历 (0)
- 查询 (1)
- 集群工具 (1)
- springMcv (1)
- ConcurrentHashMap (1)
- hashtable (1)
- cac (1)
- 树形结构 (1)
- 定时任务 (1)
- tortoiseGit (2)
- struts (11)
- shiro (31)
- log4j (3)
- struts2 (2)
- 编码 (1)
- request (3)
- Nginx (14)
- tomcat (1)
- idea (12)
- mvc (2)
- BeanUtils (2)
- image (1)
- mino (1)
- httpClient (1)
- volecity (1)
- swagger (3)
- 调错 (0)
- data (1)
- log (1)
- shell (1)
- 事物 (3)
- junit (1)
- RestTemplate (2)
- 线程 (0)
- Exception异常处理 (1)
- Exception异常注解 (1)
- lock (1)
- HashMap (1)
- 面试 (0)
- rabbitMq (1)
- rainCat (1)
- 其它 (1)
- activemq消息传送机制以及ACK机制详解 (0)
- mysql (7)
- fildder (1)
- UML (1)
- 校验 (1)
- 反射 (1)
- 切面 (1)
- springioc (1)
- urule2 (0)
- skywalking (1)
- urule (2)
- docker (2)
- 前端 (1)
- bootstrap (1)
- eureka (2)
- springcloud (16)
- jenkins (2)
- springsecurity (1)
- 数据结构 (4)
- gradle (1)
- mycat (3)
- nacos (1)
- canary (1)
- 线程池 (1)
- solr (1)
- resteasy (2)
- BI (1)
- dfs (2)
- elasticsearch (1)
- ruby (1)
- logstash (1)
- clickhouse (2)
- davinci (15)
- java (1)
- davinvi (1)
- fastdfs (1)
- vue (1)
- 《将博客搬至CSDN》 (1)
最新评论
-
nizhipeng123:
private SessionFactory sessio ...
用map接收参数的几个注意的问题
登陆:用户表-----(页面session增加,此session用上下文的request获取,传入工具类,设置)---session表------session历史表
退出:删除登录时增加的session表---页面session去除(在登陆时后台设置的session 中的当前用户,包括页面session,数据表中的session)
看别人的程序,看过程后,选择性的修订代码
sesion的工具类:
package ces.platform.system.common;
import javax.servlet.http.*;
import java.util.*;
/**
* <p>标题:
* <font class=titlefont>
* 《会话属性》类
* </font>
* <p>描述:
* <font class=descriptionfont>
* <br>会话绑定
* </font>
* <p>版本号:
* <font class=versionfont>
* Copyright (c) 2.50.2003.0925
* </font>
* <p>公司:
* <font class=companyfont>
* 上海中信信息发展有限公司
* </font>
* @author 王辉
* @version 2.50.2003.0925
*/
public class SessionProperty {
HttpSession session=null;
Hashtable table=new Hashtable();
public SessionProperty() {
}
public SessionProperty(HttpSession session) {
this.session=session;
}
public void setAttribute(String name,Object obj){
if(session!=null){
session.setAttribute(name,obj);
}else{
table.put(name,obj);
}
}
public Object getAttribute(String name){
if(session!=null){
return session.getAttribute(name);
}else{
return table.get(name);
}
}
/**
* 将context会话中的变量存入HttpSession中
* @param session
*/
public void reverseToSession(HttpSession session){
for(Enumeration enu=table.keys();enu.hasMoreElements();){
String key=(String)enu.nextElement();
session.setAttribute(key,table.get(key));
}
}
}
===利用session设置用户session====
package ces.platform.system.dbaccess;
import ces.frame.util.dao.PlatformDao;
import ces.platform.system.common.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
public class UserSession extends OperationBase implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* 静态常量:登录标志----成功
**/
public static final String LOGIN_SUCCESS = "1";
/**
* 静态常量:登录标志----不成功,并发用户数超过
**/
public static final String LOGIN_FAIL_CONN = "2";
/**
* 静态常量:登录标志----不成功,口令三次错误
**/
public static final String LOGIN_FAIL_PASSWORD = "3";
/**
* 静态常量:退出标志----未退出
**/
public static final String LOGOUT_NO = "0";
/**
* 静态常量:退出标志----正常退出
**/
public static final String LOGOUT_NORMAL = "1";
/**
* 静态常量:退出标志----注销退出
**/
public static final String LOGOUT_CANCEL = "2";
/**
* 静态常量:将会话变量存入session中
**/
public static final String STORE_SESSION = "1";
/**
* 静态常量:将会话变量存入property中
**/
public static final String STORE_PROPERTY = "2";
/**
* 成员变量:会话编号
**/
protected String sessionID;
/**
* 成员变量:会话开始时间,对应于t_sys_user_session.begin_date
**/
protected java.sql.Timestamp beginDate;
/**
* 成员变量:IP地址,对应于t_sys_user_session.ip_address
**/
protected String ipAddress;
/**
* 成员变量:用户对象
**/
protected User user;
/**
* 成员变量:网卡地址
**/
protected String macNO;
/**
* 成员变量:用户登录ID
*/
protected String loginID;
/**
* 缺省构造函数
*
**/
public UserSession() {
//
}
/**
* 构造函数1
*
* @param sessionID 会话编号
**/
public UserSession(String sessionID) {
//
this.sessionID = sessionID;
}
/**
* 构造函数2
*
* @param sessionID 会话编号
* @param beginDate 会话开始时间
* @param ipAddress IP地址
* @param macNO 网卡地址
* @param loginID 用户登录ID
* @param user 用户对象
**/
public UserSession(String sessionID ,
java.sql.Timestamp beginDate ,
String ipAddress ,
String macNO ,
String loginID,
User user) {
//
this.sessionID = sessionID;
this.beginDate = beginDate;
this.ipAddress = ipAddress;
this.macNO = macNO;
this.loginID=loginID;
this.user = user;
}
/**
* 设置会话编号
*
* @param sessionID 会话编号
**/
public void setSessionID(String sessionID) {
//
this.sessionID = sessionID;
}
/**
* 设置会话开始时间
*
* @param beginDate 会话开始时间
**/
public void setBeginDate(java.sql.Timestamp beginDate) {
//
this.beginDate = beginDate;
}
/**
* 设置IP地址
*
* @param ipAddress IP地址
**/
public void setIpAddress(String ipAddress) {
//
this.ipAddress = ipAddress;
}
/**
* 设置用户
*
* @param user 用户对象
**/
public void setUser(User user) {
//
this.user = user;
}
/**
* 设置网卡地址
*
* @param macNO 网卡地址
**/
public void setMacNO(String macNO) {
//
this.macNO = macNO;
}
/**
* 获取会话编号
*
* @return 会话编号
**/
public String getSessionID() {
//
return this.sessionID;
}
/**
* 获取会话开始时间
*
* @return 会话开始时间
**/
public java.sql.Timestamp getBeginDate() {
//
return this.beginDate;
}
/**
* 获取IP地址
*
* @return IP地址
**/
public String getIpAddress() {
//
return this.ipAddress;
}
/**
* 获取用户
*
* @return 用户对象
**/
public User getUser() {
//
return this.user;
}
/**
* 获取网卡地址
*
* @return 网卡地址
**/
public String getMacNO() {
//
return this.macNO;
}
/**
* 获取用户登录ID
* @return 登录ID
*/
public String getLoginID() {
return loginID;
}
/**
* 设置用户登录ID
* @param loginID
*/
public void setLoginID(String loginID) {
this.loginID = loginID;
}
//////////////////////////////////////////////////////////////////////////
//以下成员函数有具体应用
/**
* 验证该用户会话对象在数据库中是否存在
*
* @return true: 该对象在数据库中存在
* false: 该对象在数据空中不存在
* @throws Exception
* 如果验证有问题,将抛出异常
*/
public boolean isExist() throws Exception
{
boolean returnValue = false;
Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery = "SELECT session_id FROM " + Common.USER_SESSION_TABLE
+ " WHERE session_id = ?";
try
{
conn = PlatformDao.getDataSource().getConnection();
ps = conn.prepareStatement(strQuery);
ps.setString(1 , this.sessionID);
result = ps.executeQuery();
if (!result.next())
{
returnValue = false;
}
else
{
returnValue = true;
}
}
finally
{
close(conn, ps, result);
}
return returnValue;
}
/**
* 验证该用户会话对象在数据库中是否存在
*
* @return true: 该对象在数据库中存在
* false: 该对象在数据空中不存在
* @throws Exception
* 如果验证有问题,将抛出异常
*/
public boolean isExist(Connection con) throws Exception {
boolean returnValue = false;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery = "SELECT session_id FROM " + Common.USER_SESSION_TABLE
+ " WHERE session_id = ?";
try {
ps = con.prepareStatement(strQuery);
ps.setString(1 , this.sessionID);
result = ps.executeQuery();
if (!result.next()) {
returnValue = false;
} else {
returnValue = true;
}
} catch (SQLException se) {
throw new Exception(
"User_session.isExist(): SQLException: \n\t" + se);
} finally {
close(null, ps, result);
}
return returnValue;
}
/**
* 从数据库中重新装入该用户会话对象信息
*
* @return true: 装入成功
* false: 装入不成功
* @throws Exception
* 如果装入有问题,将抛出异常
*/
public boolean load() throws Exception
{
boolean returnValue = false;
Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery =
"SELECT ut.user_id,ut.user_name,ut.login_name,ut.flag_emp,"
+
"ut.user_cryptogram,ut.flag_lock,ut.flag_define,ut.ic_no,ut.conn_num,"
+
"ut.flag_check,ut.flag_active,ut.flag_sa,ut.show_order,ut.position_x,ut.position_y,ut.type,"
+ "ust.session_id,ust.begin_date,ust.ip_address,ust.mac_no,ust.login_id "
+ "FROM " + Common.USER_TABLE + " ut, "
+ Common.USER_SESSION_TABLE + " ust "
+ "WHERE ut.user_id = ust.user_id "
+ "AND ust.session_id = ?";
try
{
conn = PlatformDao.getDataSource().getConnection();
ps = conn.prepareStatement(strQuery);
ps.setString(1 , this.sessionID);
result = ps.executeQuery();
int i=1;
ValueAsc va=new ValueAsc(i);
if (!result.next())
{
returnValue = false;
}
else
{
i = 1;
va.setStart(i);
User uTemp = User.generateUser(result,va);
this.user = uTemp;
this.sessionID = result.getString(va.next());
this.beginDate = result.getTimestamp(va.next());
this.ipAddress = result.getString(va.next());
this.macNO = result.getString(va.next());
this.loginID=result.getString(va.next());
returnValue = true;
}
}
finally
{
close(conn, ps, result);
}
return returnValue;
}
/**
* 新建该用户会话对象
* @param conn 连接对象
* @throws Exception
* 如果新建有问题,将抛出异常
*/
protected void doNew(Connection conn) throws Exception
{
if (!isValidate()) {
throw new Exception(
"User_session.doNew(): Illegal data values for insert");
}
PreparedStatement ps = null;
String strQuery = "INSERT INTO " + Common.USER_SESSION_TABLE
+ "(session_id,user_id,begin_date,ip_address,mac_no,login_id)"
+ "VALUES (?,?,?,?,?,?)";
try {
ps = conn.prepareStatement(strQuery);
ps.setString(1 , this.sessionID);
ps.setInt(2 , this.user.getUserID());
ps.setTimestamp(3 , this.beginDate);
ps.setString(4 , this.ipAddress);
ps.setString(5 , this.macNO);
ps.setString(6 , this.loginID);
int resultCount = ps.executeUpdate();
if (resultCount != 1) {
throw new Exception(
"User_session.doNew(): ERROR Inserting data "
+ "in T_SYS_USER_SESSION INSERT !! resultCount = " +
resultCount);
}
} catch (SQLException se) {
throw new Exception(
"User_session.doNew(): SQLException while inserting new user_session; "
+ "session_id = " + this.sessionID + " :\n\t" + se);
} finally {
close(null, ps, null);
}
}
/**
* 更新该用户会话对象
* @param conn 连接对象
* @throws Exception
* 如果更新有问题,将抛出异常
*/
protected void doUpdate(Connection conn) throws Exception {
if (!isValidate()) {
throw new Exception("User_session.doUpdate(): Illegal data values for update");
}
PreparedStatement ps = null;
String strQuery = "UPDATE " + Common.USER_SESSION_TABLE + " SET "
+ "user_id = ?, begin_date = ? , "
+ "ip_address = ?, mac_no = ?, login_id= ? "
+ "WHERE session_id = ?";
//logger.debug(strQuery);
try {
ps = conn.prepareStatement(strQuery);
ps.setInt(1, this.user.getUserID());
ps.setTimestamp(2, this.beginDate);
ps.setString(3, this.ipAddress);
ps.setString(4, this.macNO);
ps.setString(5,this.loginID);
ps.setString(6, this.sessionID);
int resultCount = ps.executeUpdate();
if (resultCount != 1) {
throw new Exception("User_session.doUpdate(): ERROR updating data in T_SYS_USER_SESSION!! "
+ "resultCount = " + resultCount);
}
} catch (SQLException se) {
throw new Exception("User_session.doUpdate(): SQLException while updating user_session; "
+ "session_id = " + this.sessionID + " :\n\t" + se);
} finally {
close(null, ps, null);
}
}
/**
* 根据IP更新该用户会话对象
*
* @throws Exception
* 如果更新有问题,将抛出异常
*/
public void doUpdateByIP() throws Exception {
if (!isValidate()) {
throw new Exception("User_session.doUpdateByIP(): Illegal data values for update");
}
Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery = "UPDATE " + Common.USER_SESSION_TABLE + " SET "
+ "session_id = ?, user_id = ?, begin_date = ? , "
+ " mac_no = ?, login_id= ? "
+ "WHERE ip_address = ?";
try {
conn=PlatformDao.getDataSource().getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(strQuery);
ps.setString(1, this.sessionID);
ps.setInt(2, this.user.getUserID());
ps.setTimestamp(3, this.beginDate);
ps.setString(4, this.macNO);
ps.setString(5,this.loginID);
ps.setString(6, this.ipAddress);
int resultCount = ps.executeUpdate();
if (resultCount != 1) {
conn.rollback();
throw new Exception("User_session.doUpdateByIP(): ERROR updating data in T_SYS_USER_SESSION!! "
+ "resultCount = " + resultCount);
}
conn.commit();
} catch (SQLException se) {
if(conn!=null){
conn.rollback();
}
throw new Exception("User_session.doUpdateByIP(): SQLException while updating user_session; "
+ "session_id = " + this.sessionID + " :\n\t" + se);
} finally {
conn.setAutoCommit(true);
close(conn, ps, result);
}
}
/**
* 根据登录ID更新该用户会话对象
*
* @throws Exception
* 如果更新有问题,将抛出异常
*/
public void doUpdateByLoginID() throws Exception {
if (!isValidate()) {
throw new Exception("User_session.doUpdateByLoginID(): Illegal data values for update");
}
Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery = "UPDATE " + Common.USER_SESSION_TABLE + " SET "
+ "session_id = ?, user_id = ?, begin_date = ? , "
+ "ip_address = ?, mac_no = ? "
+ "WHERE login_id= ?";
try {
conn=PlatformDao.getDataSource().getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(strQuery);
ps.setString(1, this.sessionID);
ps.setInt(2, this.user.getUserID());
ps.setTimestamp(3, this.beginDate);
ps.setString(4, this.ipAddress);
ps.setString(5, this.macNO);
ps.setString(6,this.loginID);
int resultCount = ps.executeUpdate();
if (resultCount != 1) {
conn.rollback();
throw new Exception("User_session.doUpdateByLoginID(): ERROR updating data in T_SYS_USER_SESSION!! "
+ "resultCount = " + resultCount);
}
conn.commit();
} catch (SQLException se) {
if(conn!=null){
conn.rollback();
}
throw new Exception("User_session.doUpdateByLoginID(): SQLException while updating user_session; "
+ "session_id = " + this.sessionID + " :\n\t" + se);
} finally {
conn.setAutoCommit(true);
close(conn, ps, result);
}
}
/**
* 在数据库中删除该用户会话对象,不提交。
* @param conn 连接对象
* @throws Exception
* 如果删除有问题,将抛出异常
*/
public void doDelete(Connection conn) throws Exception {
PreparedStatement ps = null;
// Organize org = null;
String strQuery = "DELETE FROM " + Common.USER_SESSION_TABLE
+ " WHERE session_id = ?";
try {
ps = conn.prepareStatement(strQuery);
ps.setString(1, this.sessionID);
int resultCount = ps.executeUpdate();
if (resultCount != 1) {
throw new Exception("User_session.doDelete(): ERROR deleting data in T_SYS_USER_SESSION!! "
+ "resultCount = " + resultCount);
}
} catch (Exception se) {
throw new Exception("User_session.doDelete(): Exception while deleting user_session; "
+ "session_id = " + this.sessionID + " :\n\t" + se);
} finally {
close(null, ps, null);
}
}
/**
* 返回数据库中的所有用户会话对象
*
* @return 用户会话对象集合
* @throws Exception
* 如果查找有问题,将抛出异常
*/
public Vector getAllUserSessions() throws Exception
{
Vector vAllUserSessions = new Vector();
Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery = "SELECT ut.user_id,ut.user_name,ut.login_name,ut.flag_emp,"
+ "ut.user_cryptogram,ut.flag_lock,ut.flag_define,ut.ic_no,ut.conn_num,"
+ "ut.flag_check,ut.flag_active,ut.flag_sa,ut.show_order,ut.position_x,ut.position_y,ut.type,"
+ "ust.session_id,ust.begin_date,ust.ip_address,ust.mac_no,ust.login_id "
+ "FROM " + Common.USER_TABLE + " ut, "
+ Common.USER_SESSION_TABLE + " ust "
+ "WHERE ut.user_id = ust.user_id";
try {
conn = PlatformDao.getDataSource().getConnection();
ps = conn.prepareStatement(strQuery);
result = ps.executeQuery();
int i = 1;
ValueAsc va = new ValueAsc(i);
while (result.next())
{
i = 1;
va.setStart(i);
User uTemp = User.generateUser(result,va);
UserSession usTemp = UserSession.generateUserSession(result,va,uTemp);
vAllUserSessions.addElement(usTemp);
}
}
catch (SQLException se)
{
throw new Exception("User_session.getAllUserSessions(): SQLException: \n\t" + se);
}
finally
{
close(conn, ps, result);
}
return vAllUserSessions;
}
/**
* 生成查询会话对象
* @param result 查询结果集
* @param v 计数器
* @return 返回生成的对象
*/
public static UserSession generateUserSession(ResultSet result,ValueAsc v,User user) {
UserSession usTemp=new UserSession();
try{
usTemp.setSessionID(result.getString(v.next()));
usTemp.setBeginDate(result.getTimestamp(v.next()));
usTemp.setIpAddress(result.getString(v.next()));
usTemp.setMacNO(result.getString(v.next()));
usTemp.setLoginID(result.getString(v.next()));
usTemp.setUser(user);
}catch(Exception e){
e.printStackTrace();
}
return usTemp;
}
/**
* 验证存入用户会话表中的数据
*
* @return true: 验证成功
* false: 验证失败
*/
protected boolean isValidate()
{
if ( (this.sessionID == null) ||
(this.user == null) ||
(this.user.getUserID() == 0))
{
return (false);
}
else
{
return (true);
}
}
/**
* 存储会话变量,放入session还是自定义的属性集合
* @param type 1:放入session中,2:放入自定义的属性集合中
*/
public static SessionProperty setAttributeBatch(String type,HttpSession session,User user) throws Exception {
SessionProperty sp=null;
if(type.equals(UserSession.STORE_SESSION)){
sp=new SessionProperty(session);
}else{
sp=new SessionProperty();
}
//设置session变量
Vector authorities=null;
try{
authorities=user.getAuthoritiesFromContext();
//authorities=new Vector();
sp.setAttribute("authority",authorities);
sp.setAttribute("user",user);
sp.setAttribute("sa",user.getFlagSA());
}catch(Exception e){
throw e;
}
/*
for(int i=0;i<authorities.size();i++){
Authority au=(Authority)authorities.get(i);
logger.debug(au.getAuthorityID());
logger.debug(au.getPath());
}
*/
return sp;
}
/**
* 服务器启动时清空会话表
*/
public static void clearSession() throws Exception
{
try
{
Vector vAllSession = new UserSession().getAllUserSessions();
int nNum = vAllSession.size();
UserSession[] delTemp=new UserSession[nNum];
UserSessionHistory[] addTemp=new UserSessionHistory[nNum];
for (int i=0; i<nNum; i++)
{
UserSession us=(UserSession)vAllSession.get(i);
String strSessionID=us.getSessionID();
Timestamp tBegin=us.getBeginDate();
String strIP=us.getIpAddress();
String strMacNO=us.getMacNO();
User user=us.getUser();
User admin=new User(1);
admin.load();
delTemp[i]=us;
//在历史表中增加一条记录
UserSessionHistory ush=new UserSessionHistory(strSessionID);
ush.setBeginDate(tBegin);
ush.setEndDate(Common.getSysDate());
ush.setIpAddress(strIP);
ush.setMacNO(strMacNO);
ush.setUser(user);
ush.setLoginFlag(UserSession.LOGIN_SUCCESS);
ush.setLogoutFlag(UserSession.LOGOUT_NO);
ush.setCancelPerson(admin);
addTemp[i]=ush;
}
new UserSession().doDeleteBatch(delTemp);
new UserSessionHistory().doAddBatch(addTemp);
}
catch(Exception e)
{
e.printStackTrace();
throw new Exception("UserSession.clearSession(): SQLException: \n\t" + e);
}
}
}
========上面的session是这里传过来的===
package ces.frame.module.login.action;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;
import ces.frame.module.utilize.bo.ArchiveExborrowBO;
import ces.frame.util.CommonUtil;
import ces.frame.util.Transition;
import ces.frame.util.dao.CommonDao;
import ces.platform.system.action.UserSessionAction;
import ces.platform.system.common.MD5;
import ces.platform.system.common.SessionBind;
import ces.platform.system.dbaccess.LoginableTime;
import ces.platform.system.dbaccess.User;
import ces.platform.system.dbaccess.UserSession;
import ces.platform.system.form.UserSessionForm;
/**
*
* @author nfs
*
*/
public class LoginAction extends DispatchAction
{
private ArchiveExborrowBO archiveExborrowBO = null;
public ArchiveExborrowBO getArchiveExborrowBO() {
return archiveExborrowBO;
}
public void setArchiveExborrowBO(ArchiveExborrowBO archiveExborrowBO) {
this.archiveExborrowBO = archiveExborrowBO;
}
/**
* ��¼
* @param request
* @param form
* @return
*/
public ActionForward login(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
String target = "success";
String tip = "tip";
//�û������Ƿ�ҪMD5
String encrypt = "true";
HttpSession session = request.getSession(true);
DynaActionForm dForm = (DynaActionForm)form;
Vector vector = new Vector();
HashMap map = new HashMap();
map.put("urlName", "���µ�¼");
map.put("urlValue", "/login.jsp");
vector.add(map);
request.setAttribute("loginTip","1");
String loginName = dForm.get("loginName").toString();
String userPass = dForm.get("userPass").toString();
//0�������ʲ�ݵ�½ 1�����������ҵ�½
String is_szdag = dForm.get("is_szdag").toString();
if (!"false".equals(encrypt))
{
//�ѱ����ϵ�����MD5
userPass = new MD5().getMD5ofStr(userPass);
}
int userID = 0;
User user = null;
String strSessionID = "";
String strCount = "";
int intCount = 0;
UserSession usAdd = null;
try
{
int ID = new User().getUserID(loginName);
boolean flag = new LoginableTime().isLoginable();
if (ID!=1)
{
if (!flag)
{
request.setAttribute("url", vector);
request.setAttribute("message", "��ֹ��¼��");
return mapping.findForward(tip);
}
}
/*
//���Ϊ���������ҵ�½���ж��û��Ƿ���ڿɵ�½
String sql = "select count(*) from t_role_user t where t.user_id='"+ID+"' and t.role_id=(select t.role_id from t_role t where t.rolekey='CDRY')";
int count = CommonDao.getJdbcTemplate().queryForInt(sql);
if(count==0 && "1".equals(is_szdag)){
//loginName="";
}*/
//======================
}
catch (Exception e)
{
request.setAttribute("url", vector);
request.setAttribute("message", e.getMessage());
return mapping.findForward(tip);
}
strCount = (String)session.getAttribute("count");
if ((strCount!=null) && (!strCount.equals("")))
{
intCount = java.lang.Integer.parseInt(strCount);
}
// if (intCount>=3)
// {
// request.setAttribute("messageKey", messageKey + "overlogin");
// return mapping.findForward("error");
// // "�Բ������Ѿ��Ƿ���¼3�Σ����
退出:删除登录时增加的session表---页面session去除(在登陆时后台设置的session 中的当前用户,包括页面session,数据表中的session)
看别人的程序,看过程后,选择性的修订代码
sesion的工具类:
package ces.platform.system.common;
import javax.servlet.http.*;
import java.util.*;
/**
* <p>标题:
* <font class=titlefont>
* 《会话属性》类
* </font>
* <p>描述:
* <font class=descriptionfont>
* <br>会话绑定
* </font>
* <p>版本号:
* <font class=versionfont>
* Copyright (c) 2.50.2003.0925
* </font>
* <p>公司:
* <font class=companyfont>
* 上海中信信息发展有限公司
* </font>
* @author 王辉
* @version 2.50.2003.0925
*/
public class SessionProperty {
HttpSession session=null;
Hashtable table=new Hashtable();
public SessionProperty() {
}
public SessionProperty(HttpSession session) {
this.session=session;
}
public void setAttribute(String name,Object obj){
if(session!=null){
session.setAttribute(name,obj);
}else{
table.put(name,obj);
}
}
public Object getAttribute(String name){
if(session!=null){
return session.getAttribute(name);
}else{
return table.get(name);
}
}
/**
* 将context会话中的变量存入HttpSession中
* @param session
*/
public void reverseToSession(HttpSession session){
for(Enumeration enu=table.keys();enu.hasMoreElements();){
String key=(String)enu.nextElement();
session.setAttribute(key,table.get(key));
}
}
}
===利用session设置用户session====
package ces.platform.system.dbaccess;
import ces.frame.util.dao.PlatformDao;
import ces.platform.system.common.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
public class UserSession extends OperationBase implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* 静态常量:登录标志----成功
**/
public static final String LOGIN_SUCCESS = "1";
/**
* 静态常量:登录标志----不成功,并发用户数超过
**/
public static final String LOGIN_FAIL_CONN = "2";
/**
* 静态常量:登录标志----不成功,口令三次错误
**/
public static final String LOGIN_FAIL_PASSWORD = "3";
/**
* 静态常量:退出标志----未退出
**/
public static final String LOGOUT_NO = "0";
/**
* 静态常量:退出标志----正常退出
**/
public static final String LOGOUT_NORMAL = "1";
/**
* 静态常量:退出标志----注销退出
**/
public static final String LOGOUT_CANCEL = "2";
/**
* 静态常量:将会话变量存入session中
**/
public static final String STORE_SESSION = "1";
/**
* 静态常量:将会话变量存入property中
**/
public static final String STORE_PROPERTY = "2";
/**
* 成员变量:会话编号
**/
protected String sessionID;
/**
* 成员变量:会话开始时间,对应于t_sys_user_session.begin_date
**/
protected java.sql.Timestamp beginDate;
/**
* 成员变量:IP地址,对应于t_sys_user_session.ip_address
**/
protected String ipAddress;
/**
* 成员变量:用户对象
**/
protected User user;
/**
* 成员变量:网卡地址
**/
protected String macNO;
/**
* 成员变量:用户登录ID
*/
protected String loginID;
/**
* 缺省构造函数
*
**/
public UserSession() {
//
}
/**
* 构造函数1
*
* @param sessionID 会话编号
**/
public UserSession(String sessionID) {
//
this.sessionID = sessionID;
}
/**
* 构造函数2
*
* @param sessionID 会话编号
* @param beginDate 会话开始时间
* @param ipAddress IP地址
* @param macNO 网卡地址
* @param loginID 用户登录ID
* @param user 用户对象
**/
public UserSession(String sessionID ,
java.sql.Timestamp beginDate ,
String ipAddress ,
String macNO ,
String loginID,
User user) {
//
this.sessionID = sessionID;
this.beginDate = beginDate;
this.ipAddress = ipAddress;
this.macNO = macNO;
this.loginID=loginID;
this.user = user;
}
/**
* 设置会话编号
*
* @param sessionID 会话编号
**/
public void setSessionID(String sessionID) {
//
this.sessionID = sessionID;
}
/**
* 设置会话开始时间
*
* @param beginDate 会话开始时间
**/
public void setBeginDate(java.sql.Timestamp beginDate) {
//
this.beginDate = beginDate;
}
/**
* 设置IP地址
*
* @param ipAddress IP地址
**/
public void setIpAddress(String ipAddress) {
//
this.ipAddress = ipAddress;
}
/**
* 设置用户
*
* @param user 用户对象
**/
public void setUser(User user) {
//
this.user = user;
}
/**
* 设置网卡地址
*
* @param macNO 网卡地址
**/
public void setMacNO(String macNO) {
//
this.macNO = macNO;
}
/**
* 获取会话编号
*
* @return 会话编号
**/
public String getSessionID() {
//
return this.sessionID;
}
/**
* 获取会话开始时间
*
* @return 会话开始时间
**/
public java.sql.Timestamp getBeginDate() {
//
return this.beginDate;
}
/**
* 获取IP地址
*
* @return IP地址
**/
public String getIpAddress() {
//
return this.ipAddress;
}
/**
* 获取用户
*
* @return 用户对象
**/
public User getUser() {
//
return this.user;
}
/**
* 获取网卡地址
*
* @return 网卡地址
**/
public String getMacNO() {
//
return this.macNO;
}
/**
* 获取用户登录ID
* @return 登录ID
*/
public String getLoginID() {
return loginID;
}
/**
* 设置用户登录ID
* @param loginID
*/
public void setLoginID(String loginID) {
this.loginID = loginID;
}
//////////////////////////////////////////////////////////////////////////
//以下成员函数有具体应用
/**
* 验证该用户会话对象在数据库中是否存在
*
* @return true: 该对象在数据库中存在
* false: 该对象在数据空中不存在
* @throws Exception
* 如果验证有问题,将抛出异常
*/
public boolean isExist() throws Exception
{
boolean returnValue = false;
Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery = "SELECT session_id FROM " + Common.USER_SESSION_TABLE
+ " WHERE session_id = ?";
try
{
conn = PlatformDao.getDataSource().getConnection();
ps = conn.prepareStatement(strQuery);
ps.setString(1 , this.sessionID);
result = ps.executeQuery();
if (!result.next())
{
returnValue = false;
}
else
{
returnValue = true;
}
}
finally
{
close(conn, ps, result);
}
return returnValue;
}
/**
* 验证该用户会话对象在数据库中是否存在
*
* @return true: 该对象在数据库中存在
* false: 该对象在数据空中不存在
* @throws Exception
* 如果验证有问题,将抛出异常
*/
public boolean isExist(Connection con) throws Exception {
boolean returnValue = false;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery = "SELECT session_id FROM " + Common.USER_SESSION_TABLE
+ " WHERE session_id = ?";
try {
ps = con.prepareStatement(strQuery);
ps.setString(1 , this.sessionID);
result = ps.executeQuery();
if (!result.next()) {
returnValue = false;
} else {
returnValue = true;
}
} catch (SQLException se) {
throw new Exception(
"User_session.isExist(): SQLException: \n\t" + se);
} finally {
close(null, ps, result);
}
return returnValue;
}
/**
* 从数据库中重新装入该用户会话对象信息
*
* @return true: 装入成功
* false: 装入不成功
* @throws Exception
* 如果装入有问题,将抛出异常
*/
public boolean load() throws Exception
{
boolean returnValue = false;
Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery =
"SELECT ut.user_id,ut.user_name,ut.login_name,ut.flag_emp,"
+
"ut.user_cryptogram,ut.flag_lock,ut.flag_define,ut.ic_no,ut.conn_num,"
+
"ut.flag_check,ut.flag_active,ut.flag_sa,ut.show_order,ut.position_x,ut.position_y,ut.type,"
+ "ust.session_id,ust.begin_date,ust.ip_address,ust.mac_no,ust.login_id "
+ "FROM " + Common.USER_TABLE + " ut, "
+ Common.USER_SESSION_TABLE + " ust "
+ "WHERE ut.user_id = ust.user_id "
+ "AND ust.session_id = ?";
try
{
conn = PlatformDao.getDataSource().getConnection();
ps = conn.prepareStatement(strQuery);
ps.setString(1 , this.sessionID);
result = ps.executeQuery();
int i=1;
ValueAsc va=new ValueAsc(i);
if (!result.next())
{
returnValue = false;
}
else
{
i = 1;
va.setStart(i);
User uTemp = User.generateUser(result,va);
this.user = uTemp;
this.sessionID = result.getString(va.next());
this.beginDate = result.getTimestamp(va.next());
this.ipAddress = result.getString(va.next());
this.macNO = result.getString(va.next());
this.loginID=result.getString(va.next());
returnValue = true;
}
}
finally
{
close(conn, ps, result);
}
return returnValue;
}
/**
* 新建该用户会话对象
* @param conn 连接对象
* @throws Exception
* 如果新建有问题,将抛出异常
*/
protected void doNew(Connection conn) throws Exception
{
if (!isValidate()) {
throw new Exception(
"User_session.doNew(): Illegal data values for insert");
}
PreparedStatement ps = null;
String strQuery = "INSERT INTO " + Common.USER_SESSION_TABLE
+ "(session_id,user_id,begin_date,ip_address,mac_no,login_id)"
+ "VALUES (?,?,?,?,?,?)";
try {
ps = conn.prepareStatement(strQuery);
ps.setString(1 , this.sessionID);
ps.setInt(2 , this.user.getUserID());
ps.setTimestamp(3 , this.beginDate);
ps.setString(4 , this.ipAddress);
ps.setString(5 , this.macNO);
ps.setString(6 , this.loginID);
int resultCount = ps.executeUpdate();
if (resultCount != 1) {
throw new Exception(
"User_session.doNew(): ERROR Inserting data "
+ "in T_SYS_USER_SESSION INSERT !! resultCount = " +
resultCount);
}
} catch (SQLException se) {
throw new Exception(
"User_session.doNew(): SQLException while inserting new user_session; "
+ "session_id = " + this.sessionID + " :\n\t" + se);
} finally {
close(null, ps, null);
}
}
/**
* 更新该用户会话对象
* @param conn 连接对象
* @throws Exception
* 如果更新有问题,将抛出异常
*/
protected void doUpdate(Connection conn) throws Exception {
if (!isValidate()) {
throw new Exception("User_session.doUpdate(): Illegal data values for update");
}
PreparedStatement ps = null;
String strQuery = "UPDATE " + Common.USER_SESSION_TABLE + " SET "
+ "user_id = ?, begin_date = ? , "
+ "ip_address = ?, mac_no = ?, login_id= ? "
+ "WHERE session_id = ?";
//logger.debug(strQuery);
try {
ps = conn.prepareStatement(strQuery);
ps.setInt(1, this.user.getUserID());
ps.setTimestamp(2, this.beginDate);
ps.setString(3, this.ipAddress);
ps.setString(4, this.macNO);
ps.setString(5,this.loginID);
ps.setString(6, this.sessionID);
int resultCount = ps.executeUpdate();
if (resultCount != 1) {
throw new Exception("User_session.doUpdate(): ERROR updating data in T_SYS_USER_SESSION!! "
+ "resultCount = " + resultCount);
}
} catch (SQLException se) {
throw new Exception("User_session.doUpdate(): SQLException while updating user_session; "
+ "session_id = " + this.sessionID + " :\n\t" + se);
} finally {
close(null, ps, null);
}
}
/**
* 根据IP更新该用户会话对象
*
* @throws Exception
* 如果更新有问题,将抛出异常
*/
public void doUpdateByIP() throws Exception {
if (!isValidate()) {
throw new Exception("User_session.doUpdateByIP(): Illegal data values for update");
}
Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery = "UPDATE " + Common.USER_SESSION_TABLE + " SET "
+ "session_id = ?, user_id = ?, begin_date = ? , "
+ " mac_no = ?, login_id= ? "
+ "WHERE ip_address = ?";
try {
conn=PlatformDao.getDataSource().getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(strQuery);
ps.setString(1, this.sessionID);
ps.setInt(2, this.user.getUserID());
ps.setTimestamp(3, this.beginDate);
ps.setString(4, this.macNO);
ps.setString(5,this.loginID);
ps.setString(6, this.ipAddress);
int resultCount = ps.executeUpdate();
if (resultCount != 1) {
conn.rollback();
throw new Exception("User_session.doUpdateByIP(): ERROR updating data in T_SYS_USER_SESSION!! "
+ "resultCount = " + resultCount);
}
conn.commit();
} catch (SQLException se) {
if(conn!=null){
conn.rollback();
}
throw new Exception("User_session.doUpdateByIP(): SQLException while updating user_session; "
+ "session_id = " + this.sessionID + " :\n\t" + se);
} finally {
conn.setAutoCommit(true);
close(conn, ps, result);
}
}
/**
* 根据登录ID更新该用户会话对象
*
* @throws Exception
* 如果更新有问题,将抛出异常
*/
public void doUpdateByLoginID() throws Exception {
if (!isValidate()) {
throw new Exception("User_session.doUpdateByLoginID(): Illegal data values for update");
}
Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery = "UPDATE " + Common.USER_SESSION_TABLE + " SET "
+ "session_id = ?, user_id = ?, begin_date = ? , "
+ "ip_address = ?, mac_no = ? "
+ "WHERE login_id= ?";
try {
conn=PlatformDao.getDataSource().getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(strQuery);
ps.setString(1, this.sessionID);
ps.setInt(2, this.user.getUserID());
ps.setTimestamp(3, this.beginDate);
ps.setString(4, this.ipAddress);
ps.setString(5, this.macNO);
ps.setString(6,this.loginID);
int resultCount = ps.executeUpdate();
if (resultCount != 1) {
conn.rollback();
throw new Exception("User_session.doUpdateByLoginID(): ERROR updating data in T_SYS_USER_SESSION!! "
+ "resultCount = " + resultCount);
}
conn.commit();
} catch (SQLException se) {
if(conn!=null){
conn.rollback();
}
throw new Exception("User_session.doUpdateByLoginID(): SQLException while updating user_session; "
+ "session_id = " + this.sessionID + " :\n\t" + se);
} finally {
conn.setAutoCommit(true);
close(conn, ps, result);
}
}
/**
* 在数据库中删除该用户会话对象,不提交。
* @param conn 连接对象
* @throws Exception
* 如果删除有问题,将抛出异常
*/
public void doDelete(Connection conn) throws Exception {
PreparedStatement ps = null;
// Organize org = null;
String strQuery = "DELETE FROM " + Common.USER_SESSION_TABLE
+ " WHERE session_id = ?";
try {
ps = conn.prepareStatement(strQuery);
ps.setString(1, this.sessionID);
int resultCount = ps.executeUpdate();
if (resultCount != 1) {
throw new Exception("User_session.doDelete(): ERROR deleting data in T_SYS_USER_SESSION!! "
+ "resultCount = " + resultCount);
}
} catch (Exception se) {
throw new Exception("User_session.doDelete(): Exception while deleting user_session; "
+ "session_id = " + this.sessionID + " :\n\t" + se);
} finally {
close(null, ps, null);
}
}
/**
* 返回数据库中的所有用户会话对象
*
* @return 用户会话对象集合
* @throws Exception
* 如果查找有问题,将抛出异常
*/
public Vector getAllUserSessions() throws Exception
{
Vector vAllUserSessions = new Vector();
Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
String strQuery = "SELECT ut.user_id,ut.user_name,ut.login_name,ut.flag_emp,"
+ "ut.user_cryptogram,ut.flag_lock,ut.flag_define,ut.ic_no,ut.conn_num,"
+ "ut.flag_check,ut.flag_active,ut.flag_sa,ut.show_order,ut.position_x,ut.position_y,ut.type,"
+ "ust.session_id,ust.begin_date,ust.ip_address,ust.mac_no,ust.login_id "
+ "FROM " + Common.USER_TABLE + " ut, "
+ Common.USER_SESSION_TABLE + " ust "
+ "WHERE ut.user_id = ust.user_id";
try {
conn = PlatformDao.getDataSource().getConnection();
ps = conn.prepareStatement(strQuery);
result = ps.executeQuery();
int i = 1;
ValueAsc va = new ValueAsc(i);
while (result.next())
{
i = 1;
va.setStart(i);
User uTemp = User.generateUser(result,va);
UserSession usTemp = UserSession.generateUserSession(result,va,uTemp);
vAllUserSessions.addElement(usTemp);
}
}
catch (SQLException se)
{
throw new Exception("User_session.getAllUserSessions(): SQLException: \n\t" + se);
}
finally
{
close(conn, ps, result);
}
return vAllUserSessions;
}
/**
* 生成查询会话对象
* @param result 查询结果集
* @param v 计数器
* @return 返回生成的对象
*/
public static UserSession generateUserSession(ResultSet result,ValueAsc v,User user) {
UserSession usTemp=new UserSession();
try{
usTemp.setSessionID(result.getString(v.next()));
usTemp.setBeginDate(result.getTimestamp(v.next()));
usTemp.setIpAddress(result.getString(v.next()));
usTemp.setMacNO(result.getString(v.next()));
usTemp.setLoginID(result.getString(v.next()));
usTemp.setUser(user);
}catch(Exception e){
e.printStackTrace();
}
return usTemp;
}
/**
* 验证存入用户会话表中的数据
*
* @return true: 验证成功
* false: 验证失败
*/
protected boolean isValidate()
{
if ( (this.sessionID == null) ||
(this.user == null) ||
(this.user.getUserID() == 0))
{
return (false);
}
else
{
return (true);
}
}
/**
* 存储会话变量,放入session还是自定义的属性集合
* @param type 1:放入session中,2:放入自定义的属性集合中
*/
public static SessionProperty setAttributeBatch(String type,HttpSession session,User user) throws Exception {
SessionProperty sp=null;
if(type.equals(UserSession.STORE_SESSION)){
sp=new SessionProperty(session);
}else{
sp=new SessionProperty();
}
//设置session变量
Vector authorities=null;
try{
authorities=user.getAuthoritiesFromContext();
//authorities=new Vector();
sp.setAttribute("authority",authorities);
sp.setAttribute("user",user);
sp.setAttribute("sa",user.getFlagSA());
}catch(Exception e){
throw e;
}
/*
for(int i=0;i<authorities.size();i++){
Authority au=(Authority)authorities.get(i);
logger.debug(au.getAuthorityID());
logger.debug(au.getPath());
}
*/
return sp;
}
/**
* 服务器启动时清空会话表
*/
public static void clearSession() throws Exception
{
try
{
Vector vAllSession = new UserSession().getAllUserSessions();
int nNum = vAllSession.size();
UserSession[] delTemp=new UserSession[nNum];
UserSessionHistory[] addTemp=new UserSessionHistory[nNum];
for (int i=0; i<nNum; i++)
{
UserSession us=(UserSession)vAllSession.get(i);
String strSessionID=us.getSessionID();
Timestamp tBegin=us.getBeginDate();
String strIP=us.getIpAddress();
String strMacNO=us.getMacNO();
User user=us.getUser();
User admin=new User(1);
admin.load();
delTemp[i]=us;
//在历史表中增加一条记录
UserSessionHistory ush=new UserSessionHistory(strSessionID);
ush.setBeginDate(tBegin);
ush.setEndDate(Common.getSysDate());
ush.setIpAddress(strIP);
ush.setMacNO(strMacNO);
ush.setUser(user);
ush.setLoginFlag(UserSession.LOGIN_SUCCESS);
ush.setLogoutFlag(UserSession.LOGOUT_NO);
ush.setCancelPerson(admin);
addTemp[i]=ush;
}
new UserSession().doDeleteBatch(delTemp);
new UserSessionHistory().doAddBatch(addTemp);
}
catch(Exception e)
{
e.printStackTrace();
throw new Exception("UserSession.clearSession(): SQLException: \n\t" + e);
}
}
}
========上面的session是这里传过来的===
package ces.frame.module.login.action;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;
import ces.frame.module.utilize.bo.ArchiveExborrowBO;
import ces.frame.util.CommonUtil;
import ces.frame.util.Transition;
import ces.frame.util.dao.CommonDao;
import ces.platform.system.action.UserSessionAction;
import ces.platform.system.common.MD5;
import ces.platform.system.common.SessionBind;
import ces.platform.system.dbaccess.LoginableTime;
import ces.platform.system.dbaccess.User;
import ces.platform.system.dbaccess.UserSession;
import ces.platform.system.form.UserSessionForm;
/**
*
* @author nfs
*
*/
public class LoginAction extends DispatchAction
{
private ArchiveExborrowBO archiveExborrowBO = null;
public ArchiveExborrowBO getArchiveExborrowBO() {
return archiveExborrowBO;
}
public void setArchiveExborrowBO(ArchiveExborrowBO archiveExborrowBO) {
this.archiveExborrowBO = archiveExborrowBO;
}
/**
* ��¼
* @param request
* @param form
* @return
*/
public ActionForward login(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
String target = "success";
String tip = "tip";
//�û������Ƿ�ҪMD5
String encrypt = "true";
HttpSession session = request.getSession(true);
DynaActionForm dForm = (DynaActionForm)form;
Vector vector = new Vector();
HashMap map = new HashMap();
map.put("urlName", "���µ�¼");
map.put("urlValue", "/login.jsp");
vector.add(map);
request.setAttribute("loginTip","1");
String loginName = dForm.get("loginName").toString();
String userPass = dForm.get("userPass").toString();
//0�������ʲ�ݵ�½ 1�����������ҵ�½
String is_szdag = dForm.get("is_szdag").toString();
if (!"false".equals(encrypt))
{
//�ѱ����ϵ�����MD5
userPass = new MD5().getMD5ofStr(userPass);
}
int userID = 0;
User user = null;
String strSessionID = "";
String strCount = "";
int intCount = 0;
UserSession usAdd = null;
try
{
int ID = new User().getUserID(loginName);
boolean flag = new LoginableTime().isLoginable();
if (ID!=1)
{
if (!flag)
{
request.setAttribute("url", vector);
request.setAttribute("message", "��ֹ��¼��");
return mapping.findForward(tip);
}
}
/*
//���Ϊ���������ҵ�½���ж��û��Ƿ���ڿɵ�½
String sql = "select count(*) from t_role_user t where t.user_id='"+ID+"' and t.role_id=(select t.role_id from t_role t where t.rolekey='CDRY')";
int count = CommonDao.getJdbcTemplate().queryForInt(sql);
if(count==0 && "1".equals(is_szdag)){
//loginName="";
}*/
//======================
}
catch (Exception e)
{
request.setAttribute("url", vector);
request.setAttribute("message", e.getMessage());
return mapping.findForward(tip);
}
strCount = (String)session.getAttribute("count");
if ((strCount!=null) && (!strCount.equals("")))
{
intCount = java.lang.Integer.parseInt(strCount);
}
// if (intCount>=3)
// {
// request.setAttribute("messageKey", messageKey + "overlogin");
// return mapping.findForward("error");
// // "�Բ������Ѿ��Ƿ���¼3�Σ����
- 几个供参考的类.rar (8 KB)
- 下载次数: 0
相关推荐
审计数据库登陆登出触发器,审计数据库登陆失败触发器
在这个“swift demo 包含登陆登出 四个底部TabBar按钮”的项目中,我们可以看到一个典型的iOS应用框架,其中包含了用户登录、注销功能以及使用TabBar控制器来组织四个主要的屏幕。 TabBar是iOS开发中的一个重要组件...
Vue 实现登陆登出的实现示例 Vue 实现登陆登出的实现示例是一篇关于 Vue 实现登陆登出的详细示例,涵盖了登陆登出的实现过程、登陆成功后的跳转、 token 的存储和验证、登陆失效的处理等多个方面的知识点。 首先,...
这几天在学习django,django功能很强大,自带的auth,基本可以满足用户注册登陆登出,简单的用户注册登陆系统使用django auth足矣。当然也不是拿来就能用的,需要自己写登陆页面的模板,也很简单。自己尝试了一下,...
本文将深入探讨如何使用自定义按钮来实现Facebook授权登录和登出功能。 首先,我们要了解Facebook的OAuth 2.0授权流程,这是Facebook提供给开发者进行身份验证的基础。用户点击自定义按钮后,应用会通过Facebook ...
# Schoolrollmanager学生学籍管理系统,两个权限,管理员,老师功能说明 ... 2.提供了txt导入学生信息,成绩,课程信息的功能 ...10.提供了登陆登出功能,可以利用数据库权限控制指定用户所可拥有的功能
这次是做一个不使用框架,用最原始的方法实现了java-jsp的web应用,栗子呢包含增删改查、登陆登出、分页、事务处理和权限管理这几个web应用的基本要素,界面就做得很烂了,除了对齐以外就没用到CSS了,也是节约时间...
Python 图形界面设计代码,具有完整的登录、登出、提示标签。
web实例,使用express框架,实现了用户管理(注册登陆登出)功能,通过session在本地保持了登陆,通过mongoose链接mongodb实现数据持久化。(课程习作,手法拙劣,如有大佬路过,请多多指教)
用户的行为有登陆登出、获得商品列表、更改设置、删除货物、获得订单、搜索货物。临时用户的特有行为有注册。注册用户的特有行为有支付。管理员的行为有登陆登出、更改设置、更新信息、删除货物、禁止商家或者用户...
具体功能如下:1.Security functionLogin/Logout 登陆登出Password Set/Change设置/改变密码。Disk Partition Size Set/Change设置分区大小2.FOrmat:Disk Format格式化U盘Make bootable Disk制作启动...
主要功能: 提供了txt导入学生信息,成绩,课程信息的功能 提供手动录入学生信息,修改学生信息,批量修改班级及删除学生信息功能 ...提供了登陆登出功能,可以利用数据库权限控制指定用户所可拥有的功能
用户登陆登出 用户修改图像 查看已注册用户 网易云在线每日歌单 网易云每日列表 - 不懂运行,下载完可以私聊问,可远程教学 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、...
·登陆登出 ·身份认证 ·安全限制 商品分类 ·分类列表 ·增加列表 ·修改类别 ·删除类别 商品信息 ·商品列表 ·新增商品 ·图片上传 ·更新删除 ·批量上下架 订单 ·订单列表 ·地址信息 ·发货 ·订单完结 ...
【描述】"Discuz_X3.1和第三方应用同步登陆、登出"主要关注的是提高用户体验和便捷性。Discuz! 是一款非常流行的开源社区论坛软件,X3.1是其某个重要版本。通过实现与第三方应用的同步登录和登出,可以创建一个统一...
近年来,随着云计算、物联网的兴起,给网络监护运维系统造成了不小的冲击,使得网络运维...该系统主要包含以下几个模块功能,用户管理,登陆登出,设备监控,账单费用计算。紧急会议启动,召开,预约。系统网站简介等。
- **登出**:单点登出(Single Logout, SLO)需要确保用户在一处登出时,其他所有已登录的资源也同时失效。CAS支持SLO,客户端需要正确处理登出请求和清除本地会话。 - **测试**:对SSO系统进行全面的功能和安全测试...
公有模块包括登陆登出和修改密码,满足基本的账户管理需求。用户模块则包含了二手闲置商品交易、竞赛招募队员、即时通讯以及个人信息管理。二手交易功能允许用户发布、查看和管理商品;竞赛招募功能方便学生寻找比赛...