浏览器的“多个"标签-JSF 1.2广告 [英] Browser Multiples Tabs - JSF 1.2 ad
问题描述
我正在使用JSF 1.2
+ RichFaces
系统.该系统是一种博客.用户可以创建他们的博客并进行管理.可通过以下网址类型访问博客:
I'm working on a JSF 1.2
+ RichFaces
system. This system is a kind of blog. Users can create their blogs and manage them. Blogs are accessible by a url type this:
www.meublog.com/NameOfBlog
我使用一个具有会话范围的单个Managed Bean
来进行所有控件.当用户访问博客时,我使用了一个过滤器,该过滤器通过URL(用于标识正在访问的博客)将URL的ID
放入会话中,并为博客索引提供了转发.
我使用此会话ManagedBean
来控制博客视图中的所有内容.
问题在于浏览器在多个选项卡之间共享相同的会话.当用户在一个选项卡上使用www.meublog.com/julio
在另一个选项卡上使用www.meublog.com/fulano
来访问博客时,由于仅建立了一个会话,因此我无法识别两个博客.
I used a single Managed Bean
with session scope to make all controls. When the user accesses the blog, I use a filter that through the URL, which identified the blog being accessed, put the ID
of the blog in the session and gave foward to the blog index.
I used this session ManagedBean
to control everything in the view of the blog.
The problem is that the browser shares the same session between multiple tabs. When a user accesses the blog like this www.meublog.com/julio
on one tab and www.meublog.com/fulano
in another tab, I can not identify the two blogs because I have only one session established.
我想知道是否有人知道正确的方法……
I wonder to know if anyone knows the correct path to follow here ...
推荐答案
基于所面临的确切原因,您不应在会话范围内存储请求范围的信息.请使用请求范围内的受管bean代替,它根据请求URI进行初始化.您可以通过 ExternalContext
获取大多数请求的详细信息. 和/或 HttpServletRequest
.
You should not store request scoped information in the session scope for exactly the reasons you're facing. Use a request scoped managed bean instead which get initialized based on the request URI. You can get most of the request details by ExternalContext
and/or HttpServletRequest
.
例如,在bean的构造函数或@PostConstruct
方法内部:
E.g., inside bean's constructor or @PostConstruct
method:
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
// If you use suffix mapping like *.jsf
String servletPath = ec.getRequestServletPath();
// Or if you use prefix mapping like /faces/*
String pathInfo = ec.getRequestPathInfo();
// Now initialize based on the value of either servletPath or pathInfo.
另请参见:
- 如何选择正确的bean作用域?
- How to choose the right bean scope?
See also:
这篇关于浏览器的“多个"标签-JSF 1.2广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!