• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the intended URL from a request

 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand you correctly, you can use getRequestURI method to get, and possibly save it for later use.
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure it is. You need to cast the request instance to HttpServletRequest.
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Sure it is. You need to cast the request instance to HttpServletRequest.

Thanks that did the trick
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic