File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Context Parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Context Parameters" Watch "Context Parameters" New topic
Author

Context Parameters

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
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

Joined: Feb 24, 2005
Posts: 12
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


Where is Springfield? <a href="http://www.pickeringisspringfield.com" target="_blank" rel="nofollow">http://www.pickeringisspringfield.com</a><br /> <br />Portlet Tutorials & Java Certification mock exams: <a href="http://www.scja.com" target="_blank" rel="nofollow">http://www.scja.com</a><br /> <br />WebSphere Stuff: <a href="http://www.pulpjava.com" target="_blank" rel="nofollow">http://www.pulpjava.com</a>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
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

Joined: Jan 10, 2002
Posts: 61417
    
  67

What part of read-only confused you?
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
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

Joined: Jan 10, 2002
Posts: 61417
    
  67

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

Joined: Jan 10, 2002
Posts: 61417
    
  67

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

Joined: Apr 11, 2005
Posts: 744
I thought context scope and application scope were the same thing??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

"context scope" is imprecise and not meaningful. The four scopes are: page, request, session and application.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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.


Rahul Bhattacharjee
LinkedIn - Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Context Parameters