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 ...
随机推荐
- Rock-Paper-Scissors Tournament[HDU1148]
Rock-Paper-Scissors TournamentTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- XIII Open Cup named after E.V. Pankratiev. GP of Saratov
A. Box Game 注意到局面总数不超过$50000$,而且每次操作都会改变石子的奇偶性,因此按奇偶可以将状态建成二分图,然后求出最大匹配. 如果状态数是偶数,那么先手必胜,策略就是每次走匹配边, ...
- 数据仓库原理<2>:数据仓库系统的体系结构
1. 引言 本篇主要讲述数据仓库系统的体系结构与组成要素.数据集市与数据仓库之间的关系.元数据的定义与作用. 在上一篇,笔者介绍了数据仓库的定义: "数据仓库是一个面向主题的.集成的.不可更 ...
- Leetcode Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- ACM 数独
数独 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 数独是一种运用纸.笔进行演算的逻辑游戏.玩家需要根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并满足每一 ...
- 访问google,youtube
一.找到host文件 windows : C:\windows\system32\drivers\etc mac os: /private/etc linux : /etc 二.修改host文件 ht ...
- GO语言练习:channel 缓冲机制
1.代码 2.运行 3.解析 1.代码 buffer.go package main import ( "fmt" "time" ) func readThre ...
- GO语言练习:不定参数函数
1.代码 2.运行 1.代码 package main import "fmt" func MyPrintf(args ...interface{}){ for _, arg := ...
- 李洪强漫谈iOS开发[C语言-048]-打印平方表
打印平方表
- hive中导入json格式的数据(hive分区表)
hive中建立外部分区表,外部数据格式是json的如何导入呢? json格式的数据表不必含有分区字段,只需要在hdfs目录结构中体现出分区就可以了 This is all according to t ...