首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >encodeRedirectURL更改了一些字符

encodeRedirectURL更改了一些字符
EN

Stack Overflow用户
提问于 2012-04-20 02:35:11
回答 1查看 648关注 0票数 0

我在Struts2上有一个拦截器,我想为一些页面重定向到他们的ssl版本。

示例:从http://localhost/xhtml/path.do?ossesionid=value1https://localhost/xhtml/path.do?ossesionid=value1

为此,我创建了一个拦截器来做这件事:

代码语言:javascript
运行
复制
public String intercept(ActionInvocation invocation) throws Exception {

    // initialize request and response
    final ActionContext context = invocation.getInvocationContext();
    final HttpServletRequest request = (HttpServletRequest) context
            .get(StrutsStatics.HTTP_REQUEST);
    final HttpServletResponse response = (HttpServletResponse) context
            .get(StrutsStatics.HTTP_RESPONSE);

    // check scheme
    String scheme = request.getScheme().toLowerCase();

    // check method
    String method = request.getMethod().toUpperCase();

    // If the action class uses the SSLProtected marker annotation, then see
    // if we need to
    // redirect to the SSL protected version of this page
    if (invocation.getAction() instanceof SSLProtected) {

        if (HTTP_GET.equals(method) && SCHEME_HTTP.equals(scheme)) {

            // initialize https port
            String httpsPortParam = request.getSession().getServletContext().getInitParameter(HTTP_PORT_PARAM);
            int httpsPort = httpsPortParam == null ? HTTPS_PORT : Integer.parseInt(httpsPortParam);

            response.setCharacterEncoding("UTF-8");

            URI uri = new URI(SCHEME_HTTPS, null, request.getServerName(), httpsPort, response.encodeRedirectURL(request.getRequestURI()), request.getQueryString(), null);

            log.debug("Going to SSL mode, redirecting to " + uri.toString());

            response.sendRedirect(uri.toString());
            return null;
        }
    }

我的问题是我希望

代码语言:javascript
运行
复制
https://localhost/xhtml/path.do?ossesionid=value1

并得到了

代码语言:javascript
运行
复制
https://localhost/xhtml/path.do;jsessionid=value1?osessionid=value1

我完全迷路了!对谁有帮助吗?

EN

Stack Overflow用户

回答已采纳

发布于 2012-04-20 03:02:44

我强烈建议您使用S2-SSL plugin,它更灵活,并且提供了更好的支持来处理从SSL到非SSL的切换,反之亦然。

关于Jsessionid的生成,JSESSIONID cookie是在会话创建时创建/发送的。会话是在代码第一次调用request.getSession()request.getSession(true)时创建的。如果您只想获取session.You,那么有办法禁止创建Jsessionid

您可以通过多种方式禁用此id的创建,请参阅此讨论主题。

我仍然不确定您使用这个session-id会遇到什么问题,因为这在web应用程序中是很常见的情况。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10234573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档