Struts2:会话问题(反向代理后)

发布于 2024-09-12 03:42:50 字数 637 浏览 2 评论 0原文

我将会话参数存储在使用 SessionAware 接口在操作中获取的 Struts2 会话映射中。我的应用程序位于 /MyApp 路径中。

在 Apache 服务器上设置 struts2 应用程序后,使用反向代理重定向使 URL http://www .appdomain.com/ 指向我在 localhost:8080/MyApp 上的本地 tomcat,Struts2 会话处理不再起作用。我希望会话 cookie 存储为 http://localhost:8080/MyApp 的 Struts2 上下文,而不是http://www.appdomain.com/ ...

Struts2配置中有解决方案吗?或者以某种方式以编程方式更改会话 cookie?在互联网或官方文档中找不到有关此内容的任何信息。请帮忙,我已经在生产中,但我的登录不起作用;-)

I store session parameters in a Struts2 session map that I get in my actions using the SessionAware interface. My Application is in the /MyApp path.

After setting up the struts2 application on an Apache server with an inverse proxy redirect that makes the URL http://www.appdomain.com/ point to my local tomcat on localhost:8080/MyApp, Struts2 session handling doesn't work anymore. I expect that the session cookies are stored for the Struts2 context of http://localhost:8080/MyApp instead of http://www.appdomain.com/ ...

Is there a solution in Struts2 configuration? Or in programmatically changing the session cookie somehow? Couldn't find any info about this on the interwebs or in the official documentation. Please help, I'm already in production and my logins don't work ;-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

念三年u 2024-09-19 03:42:51

这是旧的,但我发现了它,并且想花 5 美分。

您可以使用的一种修复方法是编辑 web.xml 并在会话配置中设置如下内容:

<session-config>
    <session-timeout>10</session-timeout>
    <cookie-config>
        <name>MYAPPSESSIONID</name>
        <path>/</path>
    </cookie-config>
</session-config>

这会将

  • sessionid cookie 从 JSESSIONID 更改为 MYAPPSESSIONID,这样它就不会与可能在同一代理上公开的其他应用程序发生
  • 冲突cookie 适用。所以它总是会发送到服务器

希望这可以帮助其他人。

This is old but I found it and would like to drop my 5 cents.

One fix that you can use is to edit the web.xml and in the session-config set something like:

<session-config>
    <session-timeout>10</session-timeout>
    <cookie-config>
        <name>MYAPPSESSIONID</name>
        <path>/</path>
    </cookie-config>
</session-config>

This changes

  • The sessionid cookie from JSESSIONID to MYAPPSESSIONID so it will not collide with other apps that may be exposed on the same proxy
  • The path that the cookie applies. So it will always be sent to the server

Hope this may help others.

木有鱼丸 2024-09-19 03:42:51

我刚刚用一个肮脏的黑客解决了这个问题:我将会话 ID 传递给 JSP 并使用 JavaScript 来设置所需的 JSESSIONID cookie 客户端。

函数 createCookie(名称、值、天数) {
如果(天){
var date = new Date();
date.setTime(date.getTime()+(天*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
否则 var 过期 = "";
document.cookie = name+"="+value+expires+"; path=/";
}

$(文档).ready(函数() {
createCookie("JSESSIONID","",3);
});

从这个页面获取JS代码:http://www.quirksmode.org/js/cookies。 html

谢谢,问题解决了!

此致,
蒂姆

I just solved the problem with a dirty hack: I passed the Session Id to the JSP and use a javascript to set the needed JSESSIONID cookie clientside.

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

$(document).ready(function() {
createCookie("JSESSIONID","",3);
});

Got the JS code from this page: http://www.quirksmode.org/js/cookies.html

Thank you, problem solved!

Best Regards,
Tim

山田美奈子 2024-09-19 03:42:51

将其放入您的 httpd.conf

#all cookies from /MyApp are proxied to "/"
ProxyPassReverseCookiePath /MyApp /

http:// /httpd.apache.org/docs/current/mod/mod_proxy.html#proxypassreversecookiepath

Put this in your httpd.conf

#all cookies from /MyApp are proxied to "/"
ProxyPassReverseCookiePath /MyApp /

http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypassreversecookiepath

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文