• Post Reply Bookmark Topic Watch Topic
  • New Topic

attributes and paramters  RSS feed

 
william kane
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What is the difference between the request attribute and request parameter?
I have found that a request attribute is being created for every request parameter i.e when i have form that has parameters of name id and password
I am able to access the values using request.getAttribute("Id"),request.getAttribute("Password"),request.getParameter("id"),request.getParameter("password") in tomcat.Why is it needed?
Thanks in advance
William
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not needed.

On its own, no container will automatically place request parameters in scoped variables (attributes, as you called them). If this is happening, something else is responsible. Are you using a framework such as Struts?
[ July 28, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer:

What is the difference between the request attribute and request parameter?


Request parameters are the result of submitting an HTTP request with a query string that specifies the name/value pairs, or of submitting an HTML form that specifies the name/value pairs.

The name and the values are always strings.

Request attributes (more correctly called "request-scoped variables") are objects of any type that are explicitly placed on the request object via a call to the setAttribute() method. They are retrieved in Java code via the getAttribute() method and in JSP pages with Expression Language references.
[ July 28, 2005: Message edited by: Bear Bibeault ]
 
william kane
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
To answer:



Request parameters are the result of submitting an HTTP request with a query string that specifies the name/value pairs, or of submitting an HTML form that specifies the name/value pairs.

The name and the values are always strings.

Request attributes (more correctly called "request-scoped variables") are objects of any type that are explicitly placed on the request object via a call to the setAttribute() method. They are retrieved in Java code via the getAttribute() method and in JSP pages with Expression Language references.

[ July 28, 2005: Message edited by: Bear Bibeault ]


Thanx Bear Bibeault,
I am now clear with the difference b/n attributes and parameters.Yes i am using Struts.Do you think its the work of Struts to have this attributes added?
Regards,
William
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!