Fabio Entertainment
This is my personal blog, any comment are welcome.


Struts Request URI

Normally when I want to get the current page URI in JSP, I can code like this:

String currentUri = request.getRequestURI();

But unfortunately in Struts, I cannot get the current page URI with the above same code. By doing so, I will get the template file URI but not the current page URI.

For Struts, I will need to code like this:

String currentUri = (String)request.getAttribute("javax.servlet.forward.request_uri");

But how if all of my pages are in Struts or JSP? In this case, I will need to get it from Struts URI by default, else wise get from JSP URI.

String currentUri = (String)request.getAttribute("javax.servlet.forward.request_uri");
if (currentUri == null) {
currentUri = request.getRequestURI();
}

Like this, I can handle both case.

Tweet This!Share on FriendFeedTechnorati LinksSave to del.icio.usDigg This!Share on Facebook

posted by Fabio | 04/06/2008 12:03:51


Post a Comment
* You need to have JavaScript enabled in order to continue.
* Please enter your name, spammer's post will be filter out.
Author:
E-mail:
Website:
Text:
* Adds [url] and [/url] around Internet Addresses.
* [url]http://url[/url] or [url=http://url]URL text[/url].
* Adds [img] and [/img] around Internet Images.
* Images width should less than 500 pixels.
* Adds [code] and [/code] around Programming Code.
* Emoticons
:):(
:)):((
:P:D
;)X(

Contact Me

Last Update : 03/10/2009 03:55:33

LOG IN/OUT

THEME










© Copyright 2004-2010 Fabio Entertainment. All Rights Reserved.
This site is optimised for Internet Explorer 6, Firefox 2 and above.