• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Request parameter and Attribute??

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for further information click Here
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gowher,

Thanks for the code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic