Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I get the URL of request?

 
Arron Zhang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
example:
if user input:
http://www.xxxx.com/???/???.htm
How can I get "???/???.htm" in JSP
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I hope this will help u
<%
String sFname=request.getRequestURL().toString();
out.println(sFname.substring(sFname.lastIndexOf("/")+1,sFname.length()));
%>
regards
Praful
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you want the getContextPath() method of the request object.
Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arron Zhang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry,
I want go get the URL in Filter.
There's no method getRequestURL() in ServletRequest.
 
Arron Zhang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it.
In my filter,write such statment:
HttpServletRequest hrequest=(HttpServletRequest)request;
then,
String url=hrequest.getRequestURI();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic