• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request parameter and Attribute??

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers,

I'm not able to visualize the difference between the request attribute and request parameter as I have a vague idea that both are more or less the same. The scope of request attribute is also only to the page that e forward the request and the same for request parameter. So why do we need request attributes explicitly??

Anyone on this please??
 
poorna prakash parvathala
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's the explanation.

A "parameter" is a form field name/value pair passed from the HTML side of the world. Its value is a String.

An "attribute" is a Java object name/value pair passed only through the internal JavaServer processes. (I.e. it can come from a JSP or servlet but not an HTML page.) Its value is an Object.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I can understand the basic difference between the types Object type for attributes and String types for parameters. But other than this both have the same cope of making the value only visible to the page they are being forwarded. Am I right on this??
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as your request object is in scope request attributes are also in scope.You can set attribute in one servlet and get same object in another servlet.
In servlets the HttpServletRequest has lowest scope visiblity.
Next highest scope visiblity has HttpSession
Last scope ServletContext has high degree of scope visiblity.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for further information click Here
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gowher,

My question is can I set a request attribute in one servlet and forward that using Request Dispatcher to servlet 2 and can I try to access that request attribute from any other servlet to which I have not forwarded the request??

Does this sound logical??
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is called request attribute because it is available during the duration of a request, to all servlets that may be involved (directly, through forward or include). A servlet that hasn't seen the request can't access the attribute.
 
poorna prakash parvathala
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as the name implies
Request Attribute will be having the scope of Request and Request only.
it dies along with the Request.
if you want its scope to be extended .. may be you can go for broader scopes such as session.
[ January 03, 2007: Message edited by: poorna prakash parvathala ]
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

That was the answer that I was looking for. Thanks for confirming. I'm understanding it.

Good work ranchers!
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Check code above.
s2.do maps to servlet2 in DD.
when you will run Servlet1
out put will be myvars Value

But if you run Servlet2 directly (without going through Servlet1)
out put will be null.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gowher,

Thanks for the code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic