HttpServletRequest.getRequestURL() returns the forwarding url and not the request url - Weblogic

This is a discussion on HttpServletRequest.getRequestURL() returns the forwarding url and not the request url - Weblogic ; This behavior is seen in weblogic 7.0 sp2 I am using a the struts framework with the following setup : ========================================== A.html requests http://server ort/context/b.do Action B process the request and forwards to b.jsp (redirect is set to false) B.jsp ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: HttpServletRequest.getRequestURL() returns the forwarding url and not the request url

  1. HttpServletRequest.getRequestURL() returns the forwarding url and not the request url


    This behavior is seen in weblogic 7.0 sp2

    I am using a the struts framework with the following setup :
    ==========================================

    A.html requests http://serverort/context/b.do

    Action B process the request and forwards to b.jsp (redirect is set to false)

    B.jsp contains code that gathers the getRequestURL(), which returns http://serverort/context/b.jsp

    I expected the getRequestURL() to return http://serverort/context/b.do which
    is seen in the browser location bar.

    Is this the correct behavior? In the J2EE javaDocumentation the getRequestURL
    has the description "Reconstructs the URL the client used to make the request".
    Should the server actually be considered to be the client in this case? Or should
    the browser be the only client?



  2. Re: HttpServletRequest.getRequestURL() returns the forwarding url and not the request url

    Scot Hale wrote:

    > I expected the getRequestURL() to return http://serverort/context/b.do
    > which is seen in the browser location bar.


    > ... which returns http://serverort/context/b.jsp
    > Is this the correct behavior?


    Unfortunately yes. Only in Servlet 2.4 you will be able to retrieve the
    original URL through the request attributes 'javax.servlet.forward.*'.

    If possible, you may want to set your own request attribute before
    returning to struts.

    Matthias
    --
    Matthias Ernst
    Software Engineer

    CoreMedia - Smart Content Technology

  3. Re: HttpServletRequest.getRequestURL() returns the forwarding url and not the request url


    Matthias,

    To solve this I just used the Http Request Header "Referer" instead, which remains
    unchanged (always b.do). It isn't as dependable, but it seems to be working fine
    with mozilla and IE.

    I noted though that when I used tomcat 4.1.18 that it returned the b.do url, and
    it is an implementation of the 2.3 servlet spec. I guess this must be a bug
    in tomcat, or simply a spec ambiguity?

    regards,
    Scot Hale

    Matthias Ernst wrote:
    >Scot Hale wrote:
    >
    >> I expected the getRequestURL() to return http://serverort/context/b.do
    >> which is seen in the browser location bar.

    >
    >> ... which returns http://serverort/context/b.jsp
    >> Is this the correct behavior?

    >
    >Unfortunately yes. Only in Servlet 2.4 you will be able to retrieve the
    >
    >original URL through the request attributes 'javax.servlet.forward.*'.
    >
    >If possible, you may want to set your own request attribute before
    >returning to struts.
    >
    >Matthias
    >--
    >Matthias Ernst
    >Software Engineer
    >
    >CoreMedia - Smart Content Technology



+ Reply to Thread