• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting context parameter in a servlet

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

How can one set the value of a context parameter from a servlet?

Thanks
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you meant to change the value, you can't - they are read-only. In JavaEE 6, you may set new parameters before the context is initialized. There is less chance you will ever need use this method if you wisely design your application.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Red flag alert!

Why do you think you need to do this? Chances are, there's a better way to do what you are trying to accomplish.
 
Mohammed Uddin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to implement a very basic login and logout system.

So, when a user first visits my template website, the contect login state (a boolean variable) is set to false forcing the user to login - after the user logs in i would like to change the context parameter bool value to something like true - I was not aware that this is in fact a very bad thing.

Can someone please suggest how this can be done or rather are there any better practices in doing this?

Thanks
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First: use container-managed security instead of rolling your own.

If for some reason, you cannot, then you are definitely heading in the wrong direction.

Think about it for a minute. A context parameter (in addition to be read-only) is shared by all resources in the web app. So do you really think it would be appropriate for storing information for a single user? What if there's a second user? A four hundred and fifty first user? A ten thousandth?

So, again put on your thinking cap: where would be the appropriate place to store information that's pertinent for only one user?
 
Mohammed Uddin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to web technology and it's concepts.

Can you suggest how I can do this please?

Thanks.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this is for a real product, then you are not in a position to create your own security system. Learn about container-managed security and use that.

If this is just a play app for learning concepts, you need to learn about the session.
 
Mohammed Uddin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the update.

I shall look into this.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both servlet context and servlet config will be set in deployment descriptor.Servlet Config is per servlet where as servlet context param value will be shared by total webapp.

So,if you want to chane param value,you need to update in DD and need to restart the server.In real time,it is applicable for storing database values.And we cant use context params per request.
 
reply
    Bookmark Topic Watch Topic
  • New Topic