Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Context Parameters

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can context parameters be set inside a servlet or jsp?
Or MUST they be set inside web.xml, so they are available as soon as the web application is deployed?

Thanks
 
Cameron McKenzie
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The init parameters are set in the xml file, and as such, are read-only, but you can set normal read-write parameters at runtime. In fact, I usually do. It's a great scope, although a context can get out of sync across JVMs.

To put something in as soon as an application starts, you can use the appropriate context listener. That makes sure stuff is initialized before the first client request comes in.

-Cameron McKenzie
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, context parameters, like servlet init parameters, are read-only and can only be set in the deployment descriptor (web.xml).

Scoped variables placed in the application context are read-write and can be set and removed by servlet and JSP code.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just out of interest, what code would you use to add a context-parameter during run time, I don't think there is a setContextParameter method.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What part of read-only confused you?
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The part where it says

but you can set normal read-write parameters at runtime.

But I misread it, I thought it was on about the context parameters too.

So what are 'normal read-write parameters'?
I know you have request parameters resulting from forms,
and you have request,context, and session attributes, but what are these other parameters?
[ February 04, 2007: Message edited by: colin shuker ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by colin shuker:

So what are 'normal read-write parameters'?


There's no such thing. But I think that the imprecise wording was meant to mean appplication-level scoped variables, as my own reply pointed out.
[ February 04, 2007: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, scoped variables is the correct term for what I believe you are referring to as "request,context, and session attributes"; even though you left off application scope.
[ February 04, 2007: Message edited by: Bear Bibeault ]
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought context scope and application scope were the same thing??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"context scope" is imprecise and not meaningful. The four scopes are: page, request, session and application.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by colin shuker:
Can context parameters be set inside a servlet or jsp?
Or MUST they be set inside web.xml, so they are available as soon as the web application is deployed?

Thanks


I do not see any public setParameter method.So it has to be set in the web.xml and its containers responsibility to set it to the servletContext object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic