File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to get the intended URL from a request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get the intended URL from a request" Watch "How to get the intended URL from a request" New topic
Author

How to get the intended URL from a request

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Hi my filter is managing permissions for different pages. Is it possible to get the url destination of the request ?? If so how ??
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
If I understand you correctly, you can use getRequestURI method to get, and possibly save it for later use.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Bosun Bello wrote:If I understand you correctly, you can use getRequestURI method to get, and possibly save it for later use.


It seems that method is not available in
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Sure it is. You need to cast the request instance to HttpServletRequest.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Bear Bibeault wrote:Sure it is. You need to cast the request instance to HttpServletRequest.

Thanks that did the trick
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Okay so with a little debugging and trial and error i realized that the following works (both filter and servlet)


But the following just throws an exception (I Wonder what the difference is)



Exception is




Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
In the first case, you are casting, however in the second, you are calling a method on a variable that is null. Hence, the reason for the null pointer. With casting, if what you are casting returns null, your fast will return exactly that.
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Bosun Bello wrote:In the first case, you are casting, however in the second, you are calling a method on a variable that is null. Hence, the reason for the null pointer. With casting, if what you are casting returns null, your fast will return exactly that.


That makes sense.. thanks..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the intended URL from a request
 
Similar Threads
message driven bean question
Is it a POST or GET request?
Getting wrong result ,but why?
How do i get the requestet url out in a string?
How do I retrieve Javascript values from a Java servlet?