JSTL - printing the current host url

C

Christine Mayer

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
 
L

Lew

Christine said:
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.

getRemoteHost()
Returns the fully qualified name of the client or the last proxy that sent the request.

You might want
 
M

Manish Pandit

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
 
L

Lew

Manish said:
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/.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JSTL attempt in JSP 5
JSTL 0
JSTL c:out not printing value 5
Beyond trivial JSTL 1
JSTL config question 10
JSTL error 1
page counter in JSP & JSTL 0
Need help w. the JSTL c:out tag. 3

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top