File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Error while testing attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Error while testing attributes" Watch "Error while testing attributes" New topic
Author

Error while testing attributes

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

Guys,

I tried the following,



I get null printed!


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!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

But when I tried using a RequestDispatcher, I'm getting value printed??

Please help me ranchers!
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

When you use sendRedirect, you are creating new request.The browser will show you the changing URL. It is not server-side forward. Though you are calling the jsp page in same container, the request attributes will not persist in case of sendRedirect.

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

All right. Got it. Thanks for the reply!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

So it's like a new request and response objects are created and to those new objects the attribute is not yet set, so we receive a null wehn we try to print it.

Got to understand it now.
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

Request parameters and attributes are not passed to the URL used in sendRedirect.

Thanks
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

When you say it's like making a new request all over again when using a sendRedirect, it means that we get a new request and response objects. So that is the clue as to what happens with the request attribute that I've set before doing the sendRedirect.
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
You may set this idea in your mind anyway you are comfortable. The key idea is that sendRedirect fulfills that original contract (returns a response) with the client (browser) while returning a status that tells the browser to send another request to the address that you indicated in the redirect.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

Got it. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error while testing attributes