Discussions

Web tier: servlets, JSP, Web frameworks: How to get URL of the request page in servlet?

  1. How to get URL of the request page in servlet? (2 messages)

    Hi there,

    I cannot URL of the request page. Through HttpServletRequest I can only get URI of the requested servlet. Anybody has an idea of getting URL of the requesting page?

    Thanks and regards,
    Lijun
  2. check
    HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest).

    getRequestURL
    public static java.lang.StringBuffer getRequestURL(HttpServletRequest req)
    Reconstructs the URL the client used to make the request, using information in the HttpServletRequest object. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.
    Because this method returns a StringBuffer, not a string, you can modify the URL easily, for example, to append query parameters.

    This method is useful for creating redirect messages and for reporting errors.

    Parameters:
    req - a HttpServletRequest object containing the client's request
    Returns:
    a StringBuffer object containing the reconstructed URL


  3. In case anyone google's this[ Go to top ]

    You'll need to use

    request.getHeader("referer") to find out the URL of the page that generated the request to your servlet/application.