Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the appname from the web.xml

 
Mark Wa
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a java class within my app, how would I get the "appname" of my application module? (.war)

It looks like this in the web.xml


thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting context parameters is easy enough. Have a read of javax.servlet.ServletContext for the available methods.

Easier than setting a context param however is just getting it from the request.
 
Mark Wa
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. so I could do that from a servlet, but how would I do it from a POJO?
and preferably in a static safe way?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to do this from a POJO? And what do you mean by "static safe"?

If you have to, then I suppose you would need to parse web.xml yourself rather than having the servlet container do it for you. Bit of an odd requirement though.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the app name doesn't change over time, you can retrieve it at web app startup time (using a context listener), and store it in some object in a public static field.
 
Mark Wa
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds good.

I need it for printing to a log on a server. From a static method
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic