struts2 session登录

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

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

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

在action的方法中加入:

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

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

String u = (String)ActionContext.getContext().getSession().get("user");
珍惜现在,珍惜每一分,每一秒。 从不放弃,坚持。。。。。
原文地址:https://www.cnblogs.com/feiguo/p/3693302.html