• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getAttribute vs getParameter

 
Navaneetha krishnan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I sometimes find it confusing to decide between the usage of getAttribute() and getParameter(). What is the major difference between these 2 functions?

Do servlets use both these functions? What about JSP. Does JSP use these 2 functions?


Thanks in advance.
 
Kedar Dravid
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With getParameter(), you can retrieve only String values.
With getAttribute(), you can retrieve even objects.
 
Sanjay pts
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Navaneetha

YOu can read HFSJ page:186 will give nice comaprision for attribute and Parameter.
Yes you are right for request as
String request.getParameter(String)
Object request.getAttribut(String)

But attribute is far better.If you want to get/set attribute in session and Contect scope there u can set attribute only.

You read attribute and listenr chapter first and then jsp attribut together too.


As personally i had a same problem but after reading together my dought is clear.hope this will help you to clarify your dought.

Thanx
sanjay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic