aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Request parameter and Attribute?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Request parameter and Attribute??" Watch "Request parameter and Attribute??" New topic
Author

Request parameter and Attribute??

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

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??


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
poorna prakash parvathala
Greenhorn

Joined: Dec 18, 2006
Posts: 20
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.


Poorna Prakash<br /> <br />SCJP 1.4 (90%), SCWCD (planning)
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

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

Joined: Feb 07, 2005
Posts: 643
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

Joined: Feb 07, 2005
Posts: 643
for further information click Here
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

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
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
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.


Ping & DNS - my free Android networking tools app
poorna prakash parvathala
Greenhorn

Joined: Dec 18, 2006
Posts: 20
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

Joined: Sep 26, 2006
Posts: 9383
    
    2

Ulf,

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

Good work ranchers!
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643


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

Joined: Sep 26, 2006
Posts: 9383
    
    2

Gowher,

Thanks for the code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Request parameter and Attribute??