Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Obtaining JSP Name in JSP Page  RSS feed

 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Does anyone know of any way to obtain the name of the current JSP page from within the JSP Page itself ?
I am trying to integrate with a help system so that the name of the current JSP can be used to make the help 'context sensitive'. We are using the standard MVC model and so referencing the request URI just returns the name of the controller servlet. (Not very context sensitive when the same servlet is used throughout the application )
Any ideas will be very welcome as I don't really want to visit approx 250 pages in the app and explicitly define the help context.
Thanks
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bump
I assume that nobody out there has more of an idea than me then
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you certainly have access to the URL that invoked the page... but that may or may not contain the JSP name depending upon how you have your servlet mapping set up. In any case, depending upon how your URLs look, perhaps there is something within it (action names for example) that you can key off of?
As far as I know, there is no way to implicitly determine what the file a JSP page was served out of is named.
hth,
bear
 
Calina Cazangiu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I used request.getServletPath() in a similar situation and it worked.
 
Pete Harris
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy - what you're saying doesn't seem to be what happens on my webapp.
When I use getRequestURL(), it returns the URL used to make the request (ie the servlet request). However getRequestURI() returns the name of the JSP itself.
Maybe this is Tomcat specific behaviour?
[ June 10, 2003: Message edited by: Pete Harris ]
 
kavitha rama
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there's a direct way to get the jsp name. You can use request.getServletPath() to get URL and use string tokenizre to get the page name but above all is true if you sue a redirect instead of forward because URL will be changes with forward. Hope this helps
 
sai murali
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please try the following:
HttpUtils httpUtil = new HttpUtils();
String strTempURL = (httpUtil.getRequestURL(request)).toString();
by performing substring() on strTempURL you can get JSP file name.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!