Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

JSTL - printing the current host url

Thread view: 
Christine Mayer - 24 Sep 2007 13:15 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
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.