• 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

ServletContext

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why is it that getParameterValues is there only in HttpServletRequest and not in ServletContext?What if I want to associate multiple values with the same name in Context?
 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all getParameterValues() is there in the superclass ServletRequest as well...
Read the topic on request parameters once again....getParameterValues(String str) returns multiple values associated with a particular request parameter (parameter name being passed as a String argument)....there is no way you can get it by calling getParameterValues from ServletContext.....

However, you can get the context init parameter by calling getInitParameter(String s) on the servlet context.
 
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
request may contain many values for single parameter.

but ServletContext may not.Because we can only specify context's init parameters through DD. In DD you can specify only a single value for any parameter name. check this

<context-param>

<param-name>e-mail</param-name>
<param-value>raj_2566@yahoo.co.in</param-value>

</context-param>

there is no way to pass multiple values to single parameter e-mail.
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No we can set attributes programmatically to ServletContext using setAttribute right?What if I want to set multiple values with the same name?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't. You could use a collection to hold all the values you want to store under a particular name, and use that as the attribute value, but for one name there can be only one value.
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok.So I will conclude it this way
<B>
Only in case of request where we may encounter a situation where we have to send multiple values with the same name through request url from client,we have this provision.In other cases like session or context where it can be done only at the server side,we dont have this facility.
</B>
Please correct me if I am wrong
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Your question was :-
>>why is it that getParameterValues is there only in HttpServletRequest and not in ServletContext?

Cheak out the return type of the getParameterValues() .It's an array of String . As we know that request stores it's attributes in Map where key is a String and value is a object . Those are generated during run time .

>>What if I want to associate multiple values with the same name in Context?
Multiple values you can't add since ServletContext also uses Map to store it's Attributes . And it has to be a Key value pare .

Ya .......You can do one thing ..... Using ServletContextListener you can add object in ServletContext. In that way you can put a collection of object in ServletCotext also. Now as you was getting a bunch of objects in getParameterValues(), you can do the same here .

SCJP(1.4)
Preparing(SCWCD)
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't confuse parameters(associated with request) and init Paramaters(associated with servlet config and servlet context) with attributes (page scope(for JSPs only), request scope, session scope or application(or context) scope)

No attribute can have multiple values (even for a Map it's a single value- a Map)
Only request parameter can have multiple values for the same request parameter

That's it.
[ November 30, 2006: Message edited by: Sayak Banerjee ]
 
Men call me Jim. Women look past me to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic