从iframe访问会话变量 [英] Access Session variable from iframe

查看:105
本文介绍了从iframe访问会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在其中设置会话变量的jsp.

I have a jsp where I set a session variable.

<% session.setAttribute("user", CrossSession.getUser(token)); %>

但是,当我尝试在另一个jsp中读取会话变量用户"时-将其加载到iframe中(相同的主机,服务器等)-那么我只会得到NullPointerException

But when I try to read the session variable "user" within another jsp - which got loaded in an iframe (same host, server, etc.) - then I just get NullPointerException

<%= session.getAttribute("user").toString() %>

如何在iframe中获取会话变量?

How can I get my session variables in iframes?

推荐答案

某些浏览器在与iframe(尤其是Safari)共享cookie方面有严格的限制.绕过此方法的一种方法是显式传递会话ID作为iframe URL的路径参数,从而在会话管理方面利用普通Servlet容器的"URL重写"支持(默认情况下,Tomcat支持它). >

Some browsers are quite restrictive as to sharing cookies with the iframe, particularly Safari. One way of bypassing this is to explicitly pass the session ID as path parameter of iframe's URL, hereby making use of "URL rewriting" support of the average servlet container as to session management (Tomcat supports it by default out the box).

<iframe src="some.jsp;jsessionid=${pageContext.session.id}" ...>

请注意,我仍然假设您是诚实的说,iframe是由相同的主机/域提供的.

Note that I still assume that you're honest in saying that the iframe is served form the same host/domain.

这篇关于从iframe访问会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆