This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getAttribute()

 
VENKATESH NADAGOUDA
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we use getAttribute() to read the contents of querystring.If not why
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's the exact right method to use.

If you are trying and having trouble, post some of your code.

My first question would be: do you have a file upload form element in the form? If so, this will not play nicely with getAttribute()
 
Dominic Paquette
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Did you try HttpServletResponse.getQueryString() ?
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getQueryString() is actually a method of HttpServletRequest.
 
VENKATESH NADAGOUDA
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All
Firstly thank u,
now which is more advantageous getAttribute() or getParameter()
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know what? I'm totally out to lunch. I must have had a brain freeze.

If you are submitting a form, or click on a link that contains name/value pairs, then the way to get these items is with getParameter()

So if the URL to the servlet looks like:

http://www.localhost:8080/app/servlet1?name=foo&name2=bar

then here is how you access the name and name2 parameters...


When you programatically *add* things to a request or a session, the way to get these 'extra' things is within the attribute space. setAttribute() and getAttribute() are used for this purpose. Only those things that you "set" with setAttribute can be "gotten" with getAttribute.

Sorry for that confusion!
 
VENKATESH NADAGOUDA
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks Mike.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic