This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
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

Magic constants/functions?  RSS feed

 
Eddie Menuek
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In PHP the "magic constant" __FILE__ returns the current filename. Is there an equivalent in JSP? At the minute I am embedding the filename into hidden fields on forms using literal text, but this is error prone since if I rename the page and forget to update the hidden field, they are out of sync.

Sorry if I offended anyone by mentioning one of those nasty interpreted scripting languages ;)
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not offended at all.

Unlike with PHP, JSP pages get compiled into servelets.
The generated servlet is what actually gets interpreted at request time.

Tomcat is nice enough to keep the name, somewhat, intact when it creates the servlet. I'm not sure about other containers.
You can view this name with:


I've just created a JSP named "name.jsp" and ran in in Tomcat with that code.
The output was:
org.apache.jsp.name_jsp
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also...

This may not apply in your case but if you're using CVS as your revision control system, you could do what I'm doing.



If configured to do so, CVS replaces the $Id:$ keyword with the filename, version number, and some information about the last check in (user, date, etc).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!