如何将请求URL从HTTPS更新为HTTP

时间:2013-04-08 01:00:01

标签: java http servlets request

我正在尝试将来自HTTPS协议的URL请求更新为http [反之亦然]。但是我不知道如何设置我刚刚创建的新请求URL并将其传递给下一个servlet。

代码段如下,但它似乎没有按预期转发它。只有我知道如何更新请求

    String url = null;
    if (request.getScheme().equals("http")) {
        url = "https://" + request.getServerName()+":8080"+ request.getContextPath() + request.getRequestURIWithQueryString();

    System.out.println ("***************************Handling request for ************************ Remote User " + request.getRemoteUser());
    System.out.println ("***************************Handling request for ************************ Scheme " + request.getScheme());
    System.out.println ("***************************Handling request for ************************ ServerName " + request.getServerName());
    System.out.println ("***************************Handling request for ************************ ContextPath " + request.getContextPath());
    System.out.println ("***************************Handling request for ************************ ServletPath " + request.getServletPath());
    System.out.println ("***************************Handling request for ************************ URI with QueryString " + request.getRequestURIWithQueryString());

    if (request.getPathInfo() != null) {

        System.out.println ("***************************Handling request for ************************ PathInfo " + request.getPathInfo());
        url += request.getPathInfo();
        System.out.println ("***************************Handling request for ************************ URL " + url);
    }




   System.out.println ("***************************Handling request for ************************ URL 2 " + url);

  dispatcher = request.getRequestDispatcher(url);

} 

0 个答案:

没有答案