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:out 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:out value="${remoteHost}"/><c:out value="${currentUrl}"/>
Thanks in advance,
Christine
Lew - 24 Sep 2007 13:44 GMT
> I want to dynamically output the hosts url - e.g. "http:/
> www.myurl.com/" using a JSTL tag.
[quoted text clipped - 8 lines]
>
> 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.

Signature
Lew
Manish Pandit - 24 Sep 2007 18:01 GMT
> 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
[quoted text clipped - 20 lines]
>
> 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
Lew - 24 Sep 2007 22:49 GMT
Christine Mayer <Doo...@gmx.de> wrote:
>> I want to dynamically output the hosts url - e.g. "http:/www.myurl.com/" using a JSTL tag.
> 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/.

Signature
Lew
Manish Pandit - 24 Sep 2007 23:58 GMT
> Except that getRemoteHost() returns the /client/, not the /server/.
>
> --
> Lew
Oops! My bad. ${pageContext.request.serverName} should work.
-cheers,
Manish