2007-07-01
重新认识Session(续)——自己动手做试验
关键字: J2EE
我们可以设计一个Servlet,来看一看session到底是怎么工作的。
在Servlet中,可以设计这样的代码:
来查看session的工作情况。
1、session是在何种情况下创建的?
重启服务器,重新打开浏览器(这里就用IE了)。输入地址,得到输出为:
注意到,在请求报头中,没有cookie的内容。但在response响应中,有Set-Cookie的要求,这将影响到下一次浏览器的请求。
刷新一下,得到的输出为:
在Servlet中,可以设计这样的代码:
- //打印出sessionid,用来判断session是否新建
- HttpSession session = request.getSession();
- System.out.println("::SESSION ID IS : " + session.getId());
- //打印出请求报头中的内容
- Enumeration enu_req_headers = request.getHeaderNames();
- while(enu_req_headers.hasMoreElements()) {
- String headerName = (String)enu_req_headers.nextElement();
- if(!headerName.equals("cookie")) {//非Cookie报头
- System.out.println(headerName);
- }
- else {//Cookie报头
- String content = request.getHeader("cookie");
- System.out.println("::cookie : " + content);
- }
- }
- //响应中是否含有Set-Cookie,浏览器的下次提交将会受此影响
- boolean containCookie = response.containsHeader("Set-Cookie");
- System.out.println("::If The Response Contain Header:Set-Cookie? : "+containCookie);
- //判断此session是否是新创建的
- System.out.println("::If The Session is NEW : " + request.getSession().isNew());
- System.out.println();
来查看session的工作情况。
1、session是在何种情况下创建的?
重启服务器,重新打开浏览器(这里就用IE了)。输入地址,得到输出为:
- ::SESSION ID IS : 42DE852FBD9E23C5CA5E06E883D6F466
- accept
- accept-language
- accept-encoding
- user-agent
- host
- connection
- ::If The Response Contain Header:Set-Cookie? : true
- ::If The Session is NEW : true
注意到,在请求报头中,没有cookie的内容。但在response响应中,有Set-Cookie的要求,这将影响到下一次浏览器的请求。
刷新一下,得到的输出为:
评论
hunter8v
2007-07-18
public interface CardInfoDAO {
public java.util.List<cn.com.infosec.db.CardInfo> findAll ();
/**
* Either save() or update() the given instance, depending upon the value of its identifier property. By default
* the instance is always saved. This behaviour may be adjusted by specifying an unsaved-value attribute of the
* identifier property mapping.
* @param cardInfo a transient instance containing new or updated state
*/
public void saveOrUpdate(cn.com.infosec.db.CardInfo cardInfo);
/**
* Update the persistent state associated with the given identifier. An exception is thrown if there is a persistent
* instance with the same identifier in the current session.
* @param cardInfo a transient instance containing updated state
*/
public void update(cn.com.infosec.db.CardInfo cardInfo);
/**
* Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
* Session or a transient instance with an identifier associated with existing persistent state.
* @param cardInfo the instance to be removed
*/
public void delete(cn.com.infosec.db.CardInfo cardInfo);
}
hunter8v
2007-07-18
不错!
pippo25
2007-07-07
长知识了,谢谢LZ
发表评论
- 浏览: 40702 次
- 性别:

- 来自: 武汉

- 详细资料
搜索本博客
我的相册
Range表达式图示说明
共 8 张
共 8 张
最新评论
-
如果有两处分页……
谢谢了!一上google马上找到了!
-- by llleelay -
db:migrate时,Table alre ...
学习了,我以前也经常出现这种问题,只知道不行了用version重新来。看来要好好 ...
-- by mirway -
搞定dojo引起的ie6“无法 ...
hax 写道有啥不同啊? 计算绝对地址的时候结果不同。 另外,base已经是xh ...
-- by jindw -
搞定dojo引起的ie6“无法 ...
有啥不同啊?
-- by hax -
搞定dojo引起的ie6“无法 ...
确实。一旦有<base href="<%=basePath%>"> ...
-- by jindw






评论排行榜