How do I obtain a reference to a ServletContext?

Posted on 2005-02-25
Medium Priority
Last Modified: 2010-04-01

I've got several applications running within a JBoss 4 Application Server. Two of the applications are actually the same (with slightly difference configurations) so the urls' are of the form:




I'm using JMX and MBean management to control and monitor the applications however as both applications are based on the same source code they try to overwrite eachothers mbeans on the mbean server.

What I'd like to do is for the application to determine the name of the servlet context it is running under and name the appropriate MBeans accordingly.

However, I need to be able to obtain a reference to the servlet context outside of a JSP tag and Servlet.

Is there any way of getting a reference to the context the application is running in from within a normal Java class?

Thanks in advance
Question by:ads_green
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 35

Accepted Solution

TimYates earned 1000 total points
ID: 13401658
>> Is there any way of getting a reference to the context the application is running in from within a normal Java class?

Not that I know of... :-(

You'd have to pass the context through to your class...

LVL 29

Expert Comment

ID: 13402346
Not in a normal class as it does not have access to either servletconfig or request unless you pass them as TimYates mentioned.

I assume you know how to get the we app names in jsps and servlets?

LVL 35

Expert Comment

ID: 13622906
Grade C?

With no comment?

That seems more than a bit harsh :-(

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question