Two Laptop Bag
The moose likes JSP and the fly likes How can I get servlet url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How can I get servlet url" Watch "How can I get servlet url" New topic

How can I get servlet url

wei liu
Ranch Hand

Joined: Nov 19, 2008
Posts: 35

Hi all,

I am trying to use request.getRequestURL().toString() to get the current page URL. instead of getting url appears in the browse (http://localhost:8080/test/ I am getting (http://localhost:8080/test/showAbc.jsp).

I am partly know why this happened, because I set to dispatcher to showAbc.jsp in the servlet class. but can anyone tell me how to get the first url that appears in the browser?

thanks in advance

SCJP 1.6 in 2010
SCWCD5 in 2011
Arvind Sampath
Ranch Hand

Joined: May 11, 2005
Posts: 144
The method getRequestURL() would return the URL of the request submitted by the client. As I understand, the method would return the URL used for submitting the request.

Did you submit the request to showAbc.jsp?

If you want to know the URL of the page from which the request was sent, you can try reading the HTTP-REFERER header. By the way, are you trying to implement some security feature using this information? If not, why do you need this info for?

I agree. Here's the link:
subject: How can I get servlet url
It's not a secret anymore!