Struts2 框架下 session 读出来为null
我用的strust2框架,开始的时候这么写的:
在 登陆函数中(注释部分):
public String dealerLogin(){
EntityInfo entityinfo=dealerservice.dealerLogin(super.account,super.password);
if(entityinfo!=null){
/* ActionContext ac = ActionContext.getContext();我开始用的这种方式写入到session中
ac.getSession().put(KeyConstant.MANAGER,entityinfo); */
ServletActionContext.getRequest().getSession().setAttribute(KeyConstant.MANAGER,entityinfo);
return "dealertlogin";
}
else{
return "false";
}
}
用的时候的函数:
public String addAllMachCode(){
String[] machinearrs=machinearr.split(";");
int dealerId=0;
/* HttpServletRequest request=ServletActionContext.getRequest();
HttpSession session=request.getSession();
EntityInfo entityinfo=(EntityInfo) session.getAttribute(KeyConstant.MANAGER);*/这里读出来 entityinfo是null
EntityInfo entityinfo= (EntityInfo) ActionContext.getContext().getSession().get(KeyConstant.MANAGER);
Dealer dealer= entityinfo.getDealer();
dealerId=dealer.getDEALER_ID();
for (String machinecode :machinearrs) { addAMachCode(machinecode,dealerId);
}
return SUCCESS;
} 这到底是为什么了:
提取出来 第一种: 写入 ActionContext ac = ActionContext.getContext();
ac.getSession().put(KeyConstant.MANAGER,entityinfo)
读取: HttpServletRequest request=ServletActionContext.getRequest();
HttpSession session=request.getSession();
EntityInfo entityinfo=(EntityInfo) session.getAttribute(KeyConstant.MANAGER);
第二种:写入 ServletActionContext.getRequest().getSession().setAttribute(KeyConstant.MANAGER,entityinfo);
读取: EntityInfo entityinfo= (EntityInfo) ActionContext.getContext().getSession().get(KeyConstant.MANAGER);
有没有人解释下 为什么
Struts2 框架下 session 读出来为null的更多相关文章
- 关于在Struts2框架下实现文件的上传功能
struts2的配置过程 (1)在项目中加入jar包 (2)web.xml中filter(过滤器)的配置 <?xml version="1.0" encoding=" ...
- Struts2框架下的文件上传文件类型、名称约定
Struts2框架下的文件上传机制:1.通过multipart/form-data form提交文件到服务器2.文件名是通过什么地方设置的?在strust2的FileUploadInterceptor ...
- ???Struts2框架03 session的使用、登录逻辑【session工作原理】
1 登录逻辑 1.1 获取登录数据(例如:用户名.密码) 1.2 在控制层调用业务层来验证数据信息 1.3 登录成功:保存用户信息(服务器用session.浏览器用cookie),跳转到主页面 1.4 ...
- Yii2 框架下 session跨域共享互通
在项目实施过程中,往往把一个大项目进行分拆成几个独立的项目,项目用完全独立的域名和文件,可以放到不同的服务器上的独立分项目. 几个子项目共用一个登录点. 原理简单来说就是服务端session 共享, ...
- Struts2框架下表单数据的流向以及映射关系
本例框架很简单:默认页面为用户登录界面login.jsp,提交后由action类LoginAction.java来判断成功或失败,登录结果分别由success.jsp和failure.jsp呈现. 一 ...
- struts2框架下的一个简单的ajax例子
举个例子 jsp页面: <%@ page language="java" import="java.util.*" pageEncoding=" ...
- (一)Struts2框架概述
一.struts2发展历史 经过很多年发展,Struts1已经成为了高度成熟的框架,但随着时间的发展,Struts1的局限性和缺点不断的暴露出来. 现在Struts已经分化成了两个框架 ...
- Struts2、Spring MVC4 框架下的ajax统一异常处理
本文算是struts2 异常处理3板斧.spring mvc4:异常处理 后续篇章,普通页面出错后可以跳到统一的错误处理页面,但是ajax就不行了,ajax的本意就是不让当前页面发生跳转,仅局部刷新, ...
- Linux下启动tomcat报错,WARN org.apache.zookeeper.ClientCnxn - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect java.net.ConnectException:
tomcat启动完了之后,一直不停的打印这种错误信息,看表面上,应该是zk节点下的数据是空的,连接不上服务,所以一直在尝试连接,然后一直又连不上: 完整的错误信息: 407662 [usf-ZooKe ...
随机推荐
- Linux下使用vim的tips
1.如果用户不能确定vi所处的状态,可以按Esc键两次返回初始状态. 2.Fedora 17下安装与配置ssh:http://blog.csdn.net/ashuai81/article/detail ...
- 04_Swift2基础之类型安全和类型推测+字面量+类型别名
1. 类型安全和类型推测 1> 类型安全 Swift 是一个 _类型安全(type safe)_ 的语言.类型安全的语言可以让你清楚地知道代码要处理的值的类型.如果你的代码需要一个`String ...
- 【POJ3237】Tree 树链剖分+线段树
[POJ3237]Tree Description You are given a tree with N nodes. The tree's nodes are numbered 1 through ...
- Angular JS中的依赖注入
依赖注入DI angularjs中与DI相关有angular.module().angular.injector(). $injector.$provide. DI 容器3要素:服务的注册.依赖关系的 ...
- javascript的基本语法、数据结构
本篇学习资料主要讲解javascript的基本语法.数据结构 无论是传统的编程语言,还是脚本语言,都具有数据类型.常量和变量.运算符.表达式.注释语句.流程控制语句等基本元素构成,这些基本元 ...
- ORACLE11g JDBC Driver
http://blog.163.com/z_rx/blog/static/276363762011312947507/ ORACLE服务器端安装程序找到相应目录"x$\app\Adminis ...
- ACM: 强化训练-Inversion Sequence-线段树 or STL·vector
Inversion Sequence Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%lld & %llu D ...
- android中利用Socket实现手机客户端与PC端进行通信
1. 项目截图
- Java中UIManager的几种外观的详细讲解
Java'中的几种Look and Feel 1.Metal风格 (默认) String lookAndFeel = "javax.swing.plaf.metal.MetalLookAnd ...
- 直接用Qt写soap
直接用Qt写soap 最近的项目里用到了webservice, 同事用的是`gSoap`来搞的. 用这个本身没什么问题, 但这货生成的代码实非人类可读, 到处都是`__`和`_`, 看得我眼晕.... ...