Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is differnce between request.getAttribute & request.getParameter?

 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anybody please tell me what is dufference between request.getAttribute & request.getParameter?
PLease.
Thank you.
Pras
 
vijay saraf
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you will always get string from getParameter,where as getAttribute gives you Object that may be any java object.
more than this i can't say.
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
thank you for reply,
But then if I want to set request parameter into my action class, how to set it?
how to set request parameter into action class ?
Please reply..
Thank you.
pras
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is another difference:

You can both set and get attributes in your action class. With parameters, you can't set them, but only get them.

Parameters can come from one of the following:

1-Strings passed in the query string. exmple:
http://mycompany.com/myapp/myAction.do?foo=xyz&bar=abc

2-Strings passed by submitting a form. example:

<html:form action="/myAction" >
<html:text property="foo" />
<html:text property="bar" />
<html:submit property="submitButton" />
</html:form>

In both cases, request.getParameter("foo") and request.getParameter("bar") will yield results.
[ August 02, 2006: Message edited by: Merrill Higginson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic