新会话是在来自 Applet 的连续 servlet 请求和托管 bean 之间创建的吗? [英] New Session is created between consecutive servlet request from an Applet and a managed bean?

查看:17
本文介绍了新会话是在来自 Applet 的连续 servlet 请求和托管 bean 之间创建的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在applet和jsf组件之间传递参数因此,当输入文本框的值发生更改时,其绑定支持 bean 会连接到 servlet.servlet 创建一个属性并使用 (request.getSession(true)).setAttribute(name, value); 保存到 HttpSession.

I want to pass parameters betweeen applet and jsf components So when a value of a input textbox changed, its binding backing bean makes connection to a servlet. The servlet create an attribute and save to HttpSession using (request.getSession(true)).setAttribute(name, value);

然后在某个事件中,applet 将访问另一个 servlet.此 servlet 将尝试检索先前保存到 Session 的属性.

Then at some event, applet will access another servlet. This servlet will try to retrieve the Attribute saved to Session previously.

但是,每次创建新会话时,返回的属性都为空.

However, everytime, the attirbute returned is null as the new session is created instead.

我的问题是:会话是否应该持久化?(我检查了允许cookies,weblogic的会话超时)

My question is: Is the session should be persist? ( I checked allowcookies, session timeout for weblogic)

如果是,我的应用可能会出现什么问题?

If yes, what might go wrong with my app?

非常感谢您的帮助.

问候K.

推荐答案

会话由 cookie 支持.在 JSP/Servlet 环境中,cookie 名称是 jsessionid.要访问同一个会话,小程序必须在标头中使用所需的会话 cookie 来触发请求.此外,您需要确保 servlet 在相同的域和上下文中运行/侦听.

Sessions are backed by cookies. In a JSP/Servlet environment the cookie name is jsessionid. To access the same session, the applet has to fire a request with the desired session cookie in the header. Also, you need to ensure that the servlet is running/listening in the same domain and context.

首先,将会话 ID 作为参数传递给小程序:

To start, pass the session ID as a parameter to the applet:

<param name="jsessionid" value="${pageContext.session.id}">

然后,在 Applet 中连接 Servlet,如下所示:

Then, in the Applet connect the Servlet as follows:

String jsessionid = getParameter("jsessionid");
URL servlet = new URL(getCodeBase(), "servleturl");
URLConnection connection = servlet.openConnection();
connection.setRequestProperty("Cookie", "jsessionid=" + jsessionid);
// ...

这里servleturl显然应该匹配web.xml中servlet的url-pattern.这应该在 request.getSession() 上的 servlet 中返回相同的会话.

Here servleturl obviously should match servlet's url-pattern in web.xml. This should give the same session back in the servlet on request.getSession().

这篇关于新会话是在来自 Applet 的连续 servlet 请求和托管 bean 之间创建的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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