• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext

 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • 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?
 
Bryan Basham
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Renu,

The term "parameter" is overloaded in the servlet world. It can mean "HTTP request parameter" which are the name/value pairs from the HTML form that the user enters. It can also mean "servlet initialization parameter" which are the name/value pairs from the deployment descriptor in the <servlet> definitions. It can also mean "context initialization parameter" which are the name/value pairs from the deployment descriptor in the <context-param> definitions.

The ServletRequest.getParameterValues() method is for retrieving "request parameters" not for retrieving initialization parameters.

HTH,
Bryan
[ December 03, 2006: Message edited by: Bryan Basham ]
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what if I have added an attribute in servlet context and want to associate multiple values with it?
 
Atul Sawant
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Attributes are objects.

If you want to have a single attribute having multiple values you might like to use a String array (you can also use Map, List etc..), put it several string values and set that as an attribute...

String[] abc = {"You", "and", "me"}

request.setAttribute("var", abc);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic