Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 编码重定向URL更改某些字符_Java_Url_Ssl_Struts2_Interceptor - Fatal编程技术网

Java 编码重定向URL更改某些字符

Java 编码重定向URL更改某些字符,java,url,ssl,struts2,interceptor,Java,Url,Ssl,Struts2,Interceptor,我在Struts2上有一个拦截器,我想让一些页面重定向到它们的ssl版本 示例:到 为此,我创建了一个拦截器: public String intercept(ActionInvocation invocation) throws Exception { // initialize request and response final ActionContext context = invocation.getInvocationContext(); final Htt

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

示例:到

为此,我创建了一个拦截器:

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;
        }
    }
我的问题是,我希望这样

https://localhost/xhtml/path.do?ossesionid=value1
得到

https://localhost/xhtml/path.do;jsessionid=value1?osessionid=value1

我完全迷路了!帮助任何人?

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

关于JSSessionID的生成,JSSessionID cookie是在创建会话时创建/发送的。当代码第一次调用
request.getSession()
request.getSession(true)
时,将创建会话。如果您只想获取会话,您可以使用多种方法禁用Jsessionid的创建

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

我仍然不确定这个会话id面临什么问题,因为它在web应用程序中非常常见


如果希望安全访问这些页面,请不要依赖自动重定向(通过
mod_rewrite
sendRedirect
,…)。让您的链接使用https://。其他任何东西都会给你一种虚假的安全感(更多细节见)。谢谢,但这不是问题所在,我知道这是错误的方法,但我的问题是参数是错误的!你的问题到底是什么?你是说正在生成jsessionid吗?@Umeshawashi是的!我不知道为什么它会改变;这就是问题所在,我认为我的参数osessionid被重写为jsessionid,但不知道为什么!,谢谢按照Umesh指出的路径,我成功地禁用了将JSESSIONID写入我正在使用jboss的url,将其放入web.xml中,使JSESSIONID仅在web.xml add:cookie中为cookie