• Post Reply Bookmark Topic Watch Topic
  • New Topic

Where can define global variables

 
somashaker goud
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am designing a web application. I want to use hashmap object every where. is there was to declare and initialise such a way that it can be accesses in every where.

Currently I am initialising hashmapin my login page and adding it in session variable but its not looking like a best way.

is there a way we can added it in servlet context?
 
Paul Clapham
Sheriff
Posts: 21704
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a lot of possible interpretations of "everywhere" in a web app. For a start, since you're talking about servlets and sessions it's likely that you're talking about back-end processing. And not front-end processing, which one might assume given that the post is under "HTML, CSS and JavaScript". So I'll move it to the Servlets forum.

As for "everywhere", you don't seem to like the session variable idea. Is that because the map should be accessible to all users, whereas a session applies to only a single user? If so then adding it to the application context would be better. There's only one application context for a web app, and it's a instance of the type ServletContext. Despite the type name, a ServletContext doesn't apply to any particular servlet. Here's a tutorial on how to work with the application context.

However if "everywhere" is supposed to include more than one web app, your way ahead is more complicated. So let us know if that's the case and we can go into that a bit more.
 
somashaker goud
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@paul - here "everywhere" refers to for all users who ever login to my application able to access on all pages.
 
Paul Clapham
Sheriff
Posts: 21704
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like I answered your question, then. No?
 
somashaker goud
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AFAIK... in application context we can declare only string right... I want to declare hashmap.. ok let me try that and also as I said that hashmap is needed in jsp's too(as earlier said everywhere)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65417
100
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
somashaker goud wrote:AFAIK... in application context we can declare only string right

What makes you think this?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!