• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

deployed application context not working with absolute url in jsp

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Please bear with me if it has been asked earlier. I have an application named as app and deployed at tomcat 5.5.30.
In this app I have a header.jsp file which contain the absolute url link as follow

header.jsp


Now when I try to click this url from browser, I expected it to go to "http://localhost:8080/app/secure/publisher/create.htm".
But it is going to "http://localhost:8080/secure/publisher/create.htm". This jsp file is deployed under a webapp called as app(the name of the application can change however) so I thought that all absolute urls should start with the name of application context "app" but it is taking the tomcat default context "/".
I can't modify the tomcat configuration file because they are not accessible to me so I can't set the root context etc. Also my webapp can be deployed with different names depending upon the production environment or testing environment so i do not want to hard code anything in the url links like
"<a href="{application-name-here}/secure/publisher/create.htm">Add new publisher</a>"

Please help me out.
PS: Earlier in my php/html days, I saw that absolute urls worked starting from application context rather than apache local root folder so I thought it would be same in tomcat as well.

Thanks in Advance.
Ahsan
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can add <%= request.getContextPath(); %> to your url...
 
Ahsan Javed
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,
It did the magic for me. However please comment if my understanding is correct about context path.

Ahsan
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll move this out of Tomcat forum, since this isn't specific to Tomcat. Ranchers in the JSP forum will be able to help you more.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without the context path, how would the container know which application should serve the request?
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ahsan Javed wrote:Earlier in my php/html days, I saw that absolute urls worked starting from application context rather than apache local root folder so I thought it would be same in tomcat as well.



PHP and HTML have no concept of "application context" (unless maybe you are using some PHP framework or something). An absolute URL works the same in PHP and HTML as it does in a JSP.
 
Ranch Hand
Posts: 147
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using JSTL in your web app, you can use the c:url tag to do just what you're looking for:

The behavior of c:url, when the "value" starts with "/" is to map it to the root of the web app (context). So if you looked at the translated code in your browser, you should see a link similar to "/YourAppNameHere/secure/publisher/create.htm".
reply
    Bookmark Topic Watch Topic
  • New Topic