如何在 OC4J 上抑制 jsessionID?

发布于 2024-07-06 12:57:28 字数 609 浏览 10 评论 0原文

我正在将 JSF(myfaces、restfaces 和 richfaces)应用程序部署到 OC4J。 我不希望 jsessionid 出现在状态栏或 URL 地址中。 几乎在所有情况下我都设法抑制它。 我仍然遇到问题的一个情况是当第一次使用“干净”的浏览器(没有缓存、历史记录等)访问该网站时。 在这种情况下,jsessionid 会出现在每个链接上,直到单击任何链接为止,然后它就会消失,并且在浏览器的缓存再次被清除之前不会回来(即使在后续会话中)。

似乎其他人也遇到了这个问题,但我没有找到任何解决方案或解决方法:

I'm deploying a JSF (myfaces, restfaces, and richfaces) app to OC4J. I don't want the jsessionid to appear in the status bar or the URL address. I have managed to suppress it in almost all cases. The one case that I still have problems with is when the site is first visited with a "clean" browser (with no cache, history, etc.). In this case, jsessionid appears on every link until any link is clicked on, then it disappears, and will not come back (even in subsequent sessions) until the browser's cache is cleared again.

It seems others have run into this problem, but I didn't find any resolutions or work arounds:

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

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

发布评论

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

评论(1

迟月 2024-07-13 12:57:28

servlet 过滤器中的以下代码对我们有用。 这个想法是通过使用自定义响应包装器来覆盖任何 URL 重写逻辑。

public void doFilter( 
    ServletRequest req, 
    ServletResponse resp, 
    FilterChain filterChain ) 
    throws IOException, ServletException
{
    if ( req instanceof HttpServletRequest && 
         resp instanceof HttpServletResponse )
    {
        doFilter( 
            (HttpServletRequest) req, 
            (HttpServletResponse) resp, 
            filterChain );
    }
    else
    {
        filterChain.doFilter( req, resp );
    }
}

private void doFilter( 
    HttpServletRequest request, 
    HttpServletResponse response, 
    FilterChain filterChain ) 
    throws IOException, ServletException
{
    RequestHandler requestHandler = getRequestHandler( request );

    HttpServletResponse wrappedResponse = getWrappedResponse( response );

    filterChain.doFilter( request, wrappedResponse );
}

private HttpServletResponse getWrappedResponse( 
    HttpServletResponse response )
{
    return
        new HttpServletResponseWrapper( response )
        {
            public String encodeRedirectUrl( String url ) { return url; }

            public String encodeRedirectURL( String url ) { return url; }

            public String encodeUrl( String url ) { return url; }

            public String encodeURL( String url ) { return url; }
        };
}

The following code in a servlet filter has worked for us. The idea is override any URL-rewriting logic by employing a custom response wrapper.

public void doFilter( 
    ServletRequest req, 
    ServletResponse resp, 
    FilterChain filterChain ) 
    throws IOException, ServletException
{
    if ( req instanceof HttpServletRequest && 
         resp instanceof HttpServletResponse )
    {
        doFilter( 
            (HttpServletRequest) req, 
            (HttpServletResponse) resp, 
            filterChain );
    }
    else
    {
        filterChain.doFilter( req, resp );
    }
}

private void doFilter( 
    HttpServletRequest request, 
    HttpServletResponse response, 
    FilterChain filterChain ) 
    throws IOException, ServletException
{
    RequestHandler requestHandler = getRequestHandler( request );

    HttpServletResponse wrappedResponse = getWrappedResponse( response );

    filterChain.doFilter( request, wrappedResponse );
}

private HttpServletResponse getWrappedResponse( 
    HttpServletResponse response )
{
    return
        new HttpServletResponseWrapper( response )
        {
            public String encodeRedirectUrl( String url ) { return url; }

            public String encodeRedirectURL( String url ) { return url; }

            public String encodeUrl( String url ) { return url; }

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