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 ...
随机推荐
- Node.js 手册查询-5-Ejs 方法
express 中使用 //设置模板目录 app.set('views', path.join(__dirname, 'views')); //设置模板引擎 app.set('view engine' ...
- Oracle 时间,日期 类型函数及参数详解
ORACLE字符数字日期之间转化 Java代码 24 小时的形式显示出来要用 HH24 select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss' ...
- ACM 一种排序
一种排序 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复:还知道这个长方形的宽和长,编号.长.宽都是整数 ...
- Flex在Win10,Chrome浏览器上汉字乱码的问题
今天遇到一个超级郁闷的问题,之前好好的程序.但是因为客户升级了客户端操作系统.由Win7升级到Win10,就出现乱码了. 找了好多原因和办法都没解决. (1)IE浏览器正常 (2)Win7,Windo ...
- 纪念逝去的岁月——C++实现一个队列(使用类模板)
1.代码 2.运行结果 1.代码 #include <stdio.h> #include <string.h> template <typename T> clas ...
- windows与linux之间传输文件
1.使用SSH Secure Shell Client 百度网盘 下载地址 http://pan.baidu.com/s/1kTmp00J 2.使用pscp 百度网盘地址:http://pan.bai ...
- OSG动画学习
OSG动画学习 转自:http://bbs.osgchina.org/forum.php?mod=viewthread&tid=3899&_dsign=2587a6a9 学习动画,看了 ...
- Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
What it is saying is, it found the DLL, but it couldn't find a type named "namespace.User" ...
- Curl参数一览
* 目录 1. 介绍 2. curl扩展的安装 3. curl_init 4. curl_setopt 5. curl_exec 6. curl_close 7. curl_version * 介绍 ...
- Odoo attrs X2many 类型的过滤
有童鞋在群里问到 attrs 中的 many2many类型的字段该如何进行domain过滤,其实非常简单: Many2many的字段在js中获取的值的格式为[[6,false,[]]] 所以attrs ...