aspose file tools*
The moose likes JSP and the fly likes How can I get the URL of request? 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 the URL of request?" Watch "How can I get the URL of request?" New topic
Author

How can I get the URL of request?

Arron Zhang
Greenhorn

Joined: Dec 27, 2002
Posts: 15
example:
if user input:
http://www.xxxx.com/???/???.htm
How can I get "???/???.htm" in JSP


novelist & programmer
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 635
Hi I hope this will help u
<%
String sFname=request.getRequestURL().toString();
out.println(sFname.substring(sFname.lastIndexOf("/")+1,sFname.length()));
%>
regards
Praful


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
I think you want the getContextPath() method of the request object.
Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61199
    
  66

Depending upon how you have mapped your servlet you may also need request.getPathInfo().
hth,
bear
P.S. The JavaDoc for the http request class has all this info.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Arron Zhang
Greenhorn

Joined: Dec 27, 2002
Posts: 15
Sorry,
I want go get the URL in Filter.
There's no method getRequestURL() in ServletRequest.
Arron Zhang
Greenhorn

Joined: Dec 27, 2002
Posts: 15
I got it.
In my filter,write such statment:
HttpServletRequest hrequest=(HttpServletRequest)request;
then,
String url=hrequest.getRequestURI();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I get the URL of request?