年底收藏系列 Java Web工具SessionTick
package org.lambdasoft.web.support;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.lambdasoft.web.Enviroment;
public class SessionSupport {
private SessionSupport() {}
/**
* 获取当前用户Session
*
* @return httpSession
*/
public final static HttpSession getSession() {
return ServletActionContext.getRequest().getSession();
}
@SuppressWarnings("unchecked")
public final static void removeAllSession(HttpSession session) {
if(session == null)
return;
Enumeration names = session.getAttributeNames();
if(names == null)
return;
List<String> sessionNamesList = new ArrayList<String>();
while (names.hasMoreElements())
sessionNamesList.add((String)names.nextElement());
for (String sessionName : sessionNamesList) {
session.removeAttribute(sessionName);
}
}
/**
* 添加或者更新Session票据信息
*
* @param sessionTick
*/
public final static void updateSessionTick(SessionTick<TickInterface> sessionTick) {
getSession().removeAttribute(Enviroment.getEnv().getEnv("WEB_SESSION_KEY"));
getSession().setAttribute(Enviroment.getEnv().getEnv("WEB_SESSION_KEY"), sessionTick);
}
/**
* 把用户票据加入到Session
* @param account
*/
public final static void addTickToSession(TickInterface account) {
SessionTick<TickInterface> tick = new SessionTick<TickInterface>();
tick.setAccount(account);
updateSessionTick(tick);
}
}
/*
* SessionTick.java
* Copyright (C) 2009 <JustinLei@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
*
相关文档:
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
First
Parsing an XML Document
To read an XML document, you need a DocumentBuilder object, which you get from a DocumentBuilderFactory, like this:DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
You can now read a docu ......
转自:http://www.blogjava.net/action/archive/2007/04/10/109574.html
http://www.javaeye.com/topic/232662
1.设置Cookie
1Cookie cookie = new Cookie("key", "value");
2cookie.setMaxAge(60); //设置60秒生存期,如果设置为负值 ......
JAVA的设计原则
1. 接口隔离原则(ISP:Interface Segregation Principle)
定义:使用多个专门的比使用单一的总接口要好。也可以说:建立单一接口,不要建立臃肿庞大的接口。
ISP的两种定义:
◇ “Clients should not be forced to depend upon interfaces that they don't u ......
import java.util.Random;
/**
* 排序测试类
*
* 排序算法的分类如下:
* 1.插入排序(直接插入排序、折半插入排序、希尔排序);
* 2.交换排序(冒泡泡排序、快速排序);
* 3.选择排序(直接选择排序、堆排序);
* 4.归并排序;
* 5.基数排序。
&nbs ......