JSTL - printing the current host url

Discussion in 'Java' started by Christine Mayer, Sep 24, 2007.

  1. I want to dynamically output the hosts url - e.g. "http:/
    www.myurl.com/" using a JSTL tag.
    I tried several things, but didn't get it to work. I read the J2EE API
    and found request.getRemoteHost() which might be what I need (not
    sure, because on my local pc it returns 127.0.0.1 istead of
    "localhost"), however,

    <c:eek:ut value="${remoteHost}"/>

    did not work.

    Any idea what's wrong?

    More info:

    Hi, I want to create a link to send the current url by email. However,
    I am also using urlrewrite, so I cannot take the real url. Therefore I
    have a parameter "currentUrl" that gives me the current url - however
    I don't want to statically include the host's adress, I would like to
    add it dynamically, so it must be something like:
    <c:eek:ut value="${remoteHost}"/><c:eek:ut value="${currentUrl}"/>

    Thanks in advance,

    Christine
    Christine Mayer, Sep 24, 2007
    #1
    1. Advertising

  2. Christine Mayer

    Lew Guest

    Christine Mayer wrote:
    > I want to dynamically output the hosts url - e.g. "http:/
    > www.myurl.com/" using a JSTL tag.
    > I tried several things, but didn't get it to work. I read the J2EE API
    > and found request.getRemoteHost() which might be what I need (not
    > sure, because on my local pc it returns 127.0.0.1 istead of
    > "localhost"), however,
    >
    > <c:eek:ut value="${remoteHost}"/>
    >
    > did not work.
    >
    > Any idea what's wrong?


    Maybe ${request.remoteHost}?

    But that's the wrong property, if by "the host" you mean the app server host.

    <http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getRemoteHost()>
    > getRemoteHost()
    > Returns the fully qualified name of the client or the last proxy that sent the request.


    You might want
    <http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getServerName()>
    > getServerName()
    > Returns the host name of the server to which the request was sent.


    --
    Lew
    Lew, Sep 24, 2007
    #2
    1. Advertising

  3. On Sep 24, 5:15 am, Christine Mayer <> wrote:
    > I want to dynamically output the hosts url - e.g. "http:/www.myurl.com/" using a JSTL tag.
    > I tried several things, but didn't get it to work. I read the J2EE API
    > and found request.getRemoteHost() which might be what I need (not
    > sure, because on my local pc it returns 127.0.0.1 istead of
    > "localhost"), however,
    >
    > <c:eek:ut value="${remoteHost}"/>
    >
    > did not work.
    >
    > Any idea what's wrong?
    >
    > More info:
    >
    > Hi, I want to create a link to send the current url by email. However,
    > I am also using urlrewrite, so I cannot take the real url. Therefore I
    > have a parameter "currentUrl" that gives me the current url - however
    > I don't want to statically include the host's adress, I would like to
    > add it dynamically, so it must be something like:
    > <c:eek:ut value="${remoteHost}"/><c:eek:ut value="${currentUrl}"/>
    >
    > Thanks in advance,
    >
    > Christine


    Use http://${pageContext.request.remoteHost}:${pageContext.request.remotePort}
    for the server name and port. In order to get the base page URL, you
    will need to use ${pageContext.request.requestURL}. however, if you
    are using Struts and the the URL is something like /processRecord.do,
    you will end up getting the name of the actual JSP being served
    instead of /processRecord.do.

    -cheers,
    Manish
    Manish Pandit, Sep 24, 2007
    #3
  4. Christine Mayer

    Lew Guest

    Christine Mayer <> wrote:
    >> I want to dynamically output the hosts url - e.g. "http:/www.myurl.com/" using a JSTL tag.


    Manish Pandit wrote:
    > Use http://${pageContext.request.remoteHost}:${pageContext.request.remotePort}
    > for the server name and port. In order to get the base page URL, you
    > will need to use ${pageContext.request.requestURL}. however, if you
    > are using Struts and the the URL is something like /processRecord.do,
    > you will end up getting the name of the actual JSP being served
    > instead of /processRecord.do.


    Except that getRemoteHost() returns the /client/, not the /server/.

    --
    Lew
    Lew, Sep 24, 2007
    #4
  5. On Sep 24, 2:49 pm, Lew <> wrote:

    >
    > Except that getRemoteHost() returns the /client/, not the /server/.
    >
    > --
    > Lew


    Oops! My bad. ${pageContext.request.serverName} should work.

    -cheers,
    Manish
    Manish Pandit, Sep 24, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Mark Bram

    Custom JSTL that accepts JSTL expression

    Robert Mark Bram, Dec 15, 2004, in forum: Java
    Replies:
    0
    Views:
    953
    Robert Mark Bram
    Dec 15, 2004
  2. jsguru72

    JSTL c:out not printing value

    jsguru72, Sep 4, 2008, in forum: Java
    Replies:
    5
    Views:
    2,325
    Arne Vajhøj
    Sep 5, 2008
  3. DaFoot
    Replies:
    1
    Views:
    1,666
    DaFoot
    Oct 23, 2008
  4. Jack
    Replies:
    3
    Views:
    583
    Tad J McClellan
    Dec 22, 2008
  5. Replies:
    1
    Views:
    277
    Thomas 'PointedEars' Lahn
    Mar 19, 2008
Loading...

Share This Page