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 543223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:31:44+00:00 2026-05-13T10:31:44+00:00

How can I get the name of the current web app in Java EE?

  • 0

How can I get the name of the current web app in Java EE?

I’m quite comfortable with stand-alone Java, but Java EE is new to me. I’m writing some custom code to plug in to a third-party Java EE reporting package. I have multiple instances deployed on the same Tomcat server, so I have something like:

C:\
+-- tomcat6
    +-- webapps
        +-- app1
        +-- app2

So when the user goes to, let’s say, http://example.com/app1/viewReport, I want to be able to get “app1”. (And not by parsing the URL, preferrably.)

Also, if there was a way to get the root of app1 (in this example, C:\tomcat6\webapps\app1), that would be great too.

  • 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. Editorial Team
    Editorial Team
    2026-05-13T10:31:44+00:00Added an answer on May 13, 2026 at 10:31 am
    1. Getting the "name"
      =====
      It’s called the context path. If your code is running within the web app request context, you can get it by calling HttpServletRequest#getContextPath().

    2. Accessing the physical/real resource
      =====
      If you’re trying to access the contents of a file/resource in your webapp, you’re best of using one of:

    • ServletContext#getResource(String)
    • ServletContext#getResourceAsStream(String)

    It is also possible get the physical path on disk of a file/resource, given the path relative to the web app, using ServletContext#getRealPath(String), but it’s not reliable (doesn’t always work if you deploy you webapp as a WAR, for instance).

    1. Accessing class path resources
      =====
      Per your comment, you were trying to access a resource within the /WEB-INF/classes directory. Because WEB-INF/classes/* is where web application specific classes go, you can simply access it as if you were accessing any classpath resource in a Java SE application. Again, assuming your code runs within the context of the webapp, you can simply use the following:
    • Class#getResource(String)
    • Class#getResourceAsStream(String)

    In your case, you’d probably want to use the latter, and then load the Properties file via Properties#load(InputStream).

    Something along the lines of:

    Properties props = new Properties();
    props.load(getClass().getResourceAsStream("/reportCustom.properties"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to escape the quotes: <a href="http://www.example.com/download.exe" onClick="setTimeout('window.location=\"/downloading.html\"',3000);return true;">Something</a> May 15, 2026 at 8:13 am
  • Editorial Team
    Editorial Team added an answer You should be using the sharedInstance: call in each class… May 15, 2026 at 8:12 am
  • Editorial Team
    Editorial Team added an answer You can query NSDictionary with valueForKey:key //returns nil, if valued… May 15, 2026 at 8:12 am

Trending Tags

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

Top Members

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.