阻止跨网站跟踪(Prevent Cross-Site Tracking)时cookie未获取到,造成服务端获取session失败

跨域获取cookie失效解决方案

参考:http://www.bubuko.com/infodetail-357996.html

1、iphone 自带浏览器(Safari)跨网站跟踪时,需要关闭Safari设置中"阻止跨网站跟踪",如下图:
在这里插入图片描述

2、iphone 中firefox 以及Google Chrome浏览器由于涉及到用户隐私,默认时关闭

由于以上2点,自定义Session

请求时需带参数token,示例:
http://localhost:8080/test/info?token=12345678


Locale locale = new Locale("en", "US");
ActionContextUtil.getContext(token).getSession().put(Constants.WW_TRANS_I18N_LOCALE, locale);

String themeName = "default";
ActionContextUtil.getContext(token).getSession().put(Constants.SESSION_KEY_THEME_NAME, themeName);

ActionContextUtil.getContext(token).setCustomI18N();
ActionContextUtil.getContext(token).setThemeName();

配置文件config.properties

#定时任务周期(单位:毫秒):1分钟 = 1000*60
periodTime=60000

#自定义session超时时间(单位:毫秒):30分钟 = 1000*60*30
sessionTimeout=300000

web.xml 配置监听器

<listener>		
		<listener-class>cn.ding.listener.ServiceDataTaskListener</listener-class>
</listener>

创建监听器

package cn.ding.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
import cn.co.test.task.TimerManager;

public class ServiceDataTaskListener implements ServletContextListener {

	private static Logger logger = Logger.getLogger(ServiceDataTaskListener.class);

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		try {
			new TimerManager();
		} catch (Exception e) {
			logger.error(e);
		}

	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {

	}

}

定时

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值