struts2 session登录

  session:记录于服务器端的信息,当客户端传来信息时候,判断是不是指定的信息。

常见应用:判断用户是否登录。

struts具体的实现不写了,写主要的。

在action的方法中加入:

ActionContext context = ActionContext.getContext();
context.getSession().put("user",userName);

在其他的action中,直接用下面的代码接收即可。

String u = (String)ActionContext.getContext().getSession().get("user");

 

posted on 2014-04-27 09:29  端着咖啡码农  阅读(800)  评论(0编辑  收藏  举报