Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 43623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:31:27+00:00 2026-05-10T15:31:27+00:00

In Java, web apps are bundled in to WARs. By default, many servlet containers

  • 0

In Java, web apps are bundled in to WARs. By default, many servlet containers will use the WAR name as the context name for the application.

Thus myapp.war gets deployed to http://example.com/myapp.

The problem is that the webapp considers its ‘root’ to be, well, ‘root’, or simply ‘/’, whereas HTML would consider the root of your application to be ‘/myapp’.

The Servlet API and JSP have facilities to help manage this. For example, if, in a servlet, you do: response.sendRedirect(‘/mypage.jsp’), the container will prepend the context and create the url: http://example.com/myapp/mypage.jsp‘.

However, you can’t do that with, say, the IMG tag in HTML. If you do <img src=’/myimage.gif’/> you will likely get a 404, because what you really wanted was ‘/myapp/myimage.gif’.

Many frameworks have JSP tags that are context aware as well, and there are different ways of making correct URLs within JSP (none particularly elegantly).

It’s a nitty problem for coders to jump in an out of when to use an ‘App Relative’ url, vs an absolute url.

Finally, there’s the issue of Javascript code that needs to create URLs on the fly, and embedded URLs within CSS (for background images and the like).

I’m curious what techniques others use to mitigate and work around this issue. Many simply punt and hard code it, either to server root or to whatever context they happen to be using. I already know that answer, that’s not what I’m looking for.

What do you do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:31:28+00:00Added an answer on May 10, 2026 at 3:31 pm

    You can use JSTL for creating urls.

    For example, <c:url value='/images/header.jpg' /> will prefix the context root.

    With CSS, this usually isn’t an issue for me.

    I have a web root structure like this:

    /css
    /images

    In the CSS file, you then just need to use relative URLs (../images/header.jpg) and it doesn’t need to be aware of the context root.

    As for JavaScript, what works for me is including some common JavaScript in the page header like this:

    <script type='text/javascript'> var CONTEXT_ROOT = '<%= request.getContextPath() %>'; </script> 

    Then you can use the context root in all your scripts (or, you can define a function to build paths – may be a bit more flexible).

    Obviously this all depends on your using JSPs and JSTL, but I use JSF with Facelets and the techniques involved are similar – the only real difference is getting the context root in a different way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Related Questions

Loading...

Sidebar

Ask A Question

Stats

  • Questions 54k
  • Answers 54k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer fn:lower-case is defined in XQuery 1.0 and XPath 2.0. XSLT… May 11, 2026 at 7:23 am
  • added an answer This looks like one. Though, by the looks of description… May 11, 2026 at 7:23 am
  • added an answer update 2: rdiscount 1.3.4 installs fine on Solaris, thanks to… May 11, 2026 at 7:23 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.