This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Getting root of my application? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting root of my application?" Watch "Getting root of my application?" New topic
Author

Getting root of my application?

Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
Hi!
I am having problems retrieving the root of my application.
What happens is, I have a tag which checks if the user is logged in or not, and if not, then it offers him to "click here" to log in, where "click here" should point to "approot/account/login.jsp"...
Right now, to access my login JSP, the following URL is needed:
"http://localhost:8080/myapp/account/login.jsp"
And if I write my <a href> as absolute path (href="/account/login.jsp"), then it points to
"http://localhost:8080/account/login.jsp"
And that's not what I want (cuz I'll obviously get a 404). I can "force" it to do href="/myapp/account/login.jsp", and it will work, but what if in the future I change the name of myapp to something different? Or get a domain name, where myapp doesn't even participate?
So, I wanted to know if there's any good way to do it (except for writing a specific URL in every single file)...
I was trying to access ServletContext.get... but there doesn't seem to be any useful methods for doing it... So, how would you go around this problem?
Any help is appreciate, thank you!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

request.getContextPath()
[ February 10, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

request.getContextPath()
Look up the API docs for HttpServletRequest interface
docs


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
Thx !!!
 
 
subject: Getting root of my application?
 
Similar Threads
Running JSP from outside tomcat\webapps\ROOT
page cannot be displayed error
Problem with the Contextpath in the url
J2EE - Relative Path Vs Absolute Path
Pulling my hair out over Tomcat servlets