如何让 servlet 容器从查询字符串而不是 URL 中读取 JSESSIONID

发布于 2024-12-02 04:29:15 字数 716 浏览 3 评论 0原文

我需要能够通过将 JSESSIONID 指定为 url 查询字符串的参数而不是 URL 本身的一部分来维护会话。

换句话说,我需要维护这样的会话

http://myserver.com?jsessionid=A463B23BC4F2342FA

http://myserver.com;jsessionid=A463B23BC4F2342FA

对于 servlet 容器,我同时使用 tomcat 6.0 和 weblogic 10.3

原因:

我正在创建一个 Google 地球网络链接,这需要我为客户端发出的请求保留一个会话。 Google 地球不支持 cookie,并且似乎无法更改它用于发出请求的 URL。我只能通过将以下内容添加到服务器响应中的 kml 来告诉它在后续请求中附加查询字符串参数

<NetworkLinkControl>
    <cookie>JSESSIONID=A463B23BC4F2342FA</cookie>
</NetworkLinkControl>

I need to be able to maintain a session by having the JSESSIONID specified as a parameter of the query string of the url rather than part of the URL itself.

I other words I need to maintain a session like this

http://myserver.com?jsessionid=A463B23BC4F2342FA

rather than

http://myserver.com;jsessionid=A463B23BC4F2342FA

For a servlet container I'm using both tomcat 6.0 and weblogic 10.3

Reason:

I'm creating a Google Earth network link which requires me to keep a session for the requests a client makes. Google Earth doesn't support cookies and it appears there is no way to change the url that it uses to make requests. I can only tell it to append a query string parameter on subsequent requests by adding the following to the kml in my server responses

<NetworkLinkControl>
    <cookie>JSESSIONID=A463B23BC4F2342FA</cookie>
</NetworkLinkControl>

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

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

发布评论

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

评论(2

眉目亦如画i 2024-12-09 04:29:15

不可能。我会在您这边创建一个 filter ,每当 URL 到达时,它会将请求重定向到正确的 URL <查询字符串中的 code>JSESSIONID。

基本启动示例:

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    if ("GET".equals(request.getMethod()) && request.getParameter("JSESSIONID") != null) {
        response.sendRedirect(request.getRequestURL().append(";JSESSIONID=")
            .append(request.getParameter("JSESSIONID")).toString());
    } else {
        chain.doFilter(request, response);
    }
}

将其映射到 URL 模式,该模式涵盖可能由该站点发起的请求。或者,如果没有,则仅在 /* 上。

Not possible. I'd create on your side a filter which redirects the request to the proper URL whenever an URL arrives with the JSESSIONID in the query string.

Basic kickoff example:

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    if ("GET".equals(request.getMethod()) && request.getParameter("JSESSIONID") != null) {
        response.sendRedirect(request.getRequestURL().append(";JSESSIONID=")
            .append(request.getParameter("JSESSIONID")).toString());
    } else {
        chain.doFilter(request, response);
    }
}

Map this on an URL pattern which covers requests which could potentially originate by that site. Or if there is none, just on /*.

迷路的信 2024-12-09 04:29:15

为此,我们创建了定制 Tomcat Valve。它非常简单,但是特定于 Tomcat。

We have created custom Tomcat Valve for this purpose. It's pretty straightforward, but Tomcat-specific.

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