新会话是在 Applet 和托管 bean 的连续 servlet 请求之间创建的吗?
我想在小程序和jsf组件之间传递参数 因此,当输入文本框的值发生更改时,其绑定支持 bean 会与 servlet 建立连接。 servlet 创建一个属性并使用 (request.getSession(true)).setAttribute(name, value); 保存到 HttpSession;
然后在某些事件中,applet 将访问另一个 servlet。该 servlet 将尝试检索先前保存到会话中的属性。
但是,每次创建新会话时,返回的属性都是 null。
我的问题是:会话应该持续吗? (我检查了allowcookies、weblogic 的会话超时)
如果是,我的应用程序可能会出现什么问题?
非常感谢您的帮助。
问候 K.
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);
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.
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?
Thanks a lot for your help.
Regards
K.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
会话由 cookie 支持。在 JSP/Servlet 环境中,cookie 名称是
jsessionid
。要访问同一会话,小程序必须发出标头中包含所需会话 cookie 的请求。另外,您需要确保 servlet 在相同的域和上下文中运行/侦听。首先,将会话 ID 作为参数传递给 applet:
然后,在 Applet 中按如下方式连接 Servlet:
这里
servleturl
显然应该与 servlet 中的url-pattern
相匹配代码> web.xml 。这应该在request.getSession()
上的 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.To start, pass the session ID as a parameter to the applet:
Then, in the Applet connect the Servlet as follows:
Here
servleturl
obviously should match servlet'surl-pattern
inweb.xml
. This should give the same session back in the servlet onrequest.getSession()
.虽然 @BalusC 是正确的(像往常一样),但我认为 JSessionId 没有被发送到 servlet 也可能还有另一个原因。
当使用 Weblogic 时(我想你也是这么做的),默认值是
仅 cookie-http
设置为 true,意味着在请求 javascript 或 applet 等资源时,它不会发送 cookie,这意味着 applet 发送的每个请求都将包含一个新的会话 ID,从而使其无法使用粘性会话。
更多信息可以在这里找到:https://forums.oracle.com/message/3747820
Although @BalusC is correct (as usual), I think there could also be another reason why the the JSessionId is not being sent to the servlet.
When using Weblogic (and I suppose you do), the default value of
cookie-http-only
is set to true, meaning it won't send cookies when requesting resources like javascript or applets, meaning every request that the applet sends will include a fresh session ID, making it unable to use sticky sessions.
More information can be found here: https://forums.oracle.com/message/3747820
要与 servlet 建立工作会话,包含小程序的页面必须由 servlet“提供服务”。
此时您可以成功打开与 servlet 的连接。
但这种方法适用于tomcat6;您拥有会话的完全访问权限。
通过避免 Tomcat7 会话固定,当小程序发布其请求时会创建一个新会话...
To established a working session with the servlet, the page containing your applet must have been "served by" the servlet.
At this point you can open a succesfull connection to the servlet.
But this approach work up to tomcat6; You have full access to the session.
With Tomcat7 session fixation avoidance, a new session is created at when the applet posts its request...