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 ...
随机推荐
- BZOJ4367 : [IOI2014]holiday假期
设 $fl[i]$表示从$S$向左走,用了不超过$i$天且不回头的最大收益. $fr[i]$表示从$S$向右走,用了不超过$i$天且不回头的最大收益. $gl[i]$表示从$S$向左走,用了不超过$i ...
- HDU 3090 (贪心)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3090 题目大意:一共n段路.每段路每千米都会被抢劫一定数量,可以雇佣武士护卫m千米.问最少被抢劫数量 ...
- JavaScript实现存储HTML字符串
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- ACM +-字符串
+-字符串 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 Shiva得到了两个只有加号和减号的字符串,字串长度相同.Shiva一次可以把一个加号和它相邻的减号交换. ...
- Codeforces Round #233 (Div. 2) B. Red and Blue Balls
#include <iostream> #include <string> using namespace std; int main(){ int n; cin >&g ...
- ACM Minimum Inversion Number 解题报告 -线段树
C - Minimum Inversion Number Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- jquery delay()介绍及使用指南
.delay()是用来在jQuery动画效果和类似队列中是最好的.但是,由于其本身的限制,比如无法取消延时——.delay(),它不是JavaScript的原生 setTimeout函数的替代品,这可 ...
- CF 335B. Palindrome(DP)
题目链接 挺好玩的一个题,1Y... #include <cstdio> #include <cstring> #include <iostream> using ...
- SQL中union运算操作的理解
在SQL中,对于并运算,可以使用union关键字. 例如: SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FRO ...
- java输入一个字符串,打印出该字符串中字符的所有排列,随机打乱排序
import java.util.ArrayList;import java.util.Collections;import java.util.List; public class Test7{ ...