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

Request Attribute confusion

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 8795

Guys,

I tried the following,

My test.jsp,


But if I comment Line 1, I'm getting a null pointer?? I know the request.getAttribute("jothi") in the System.out.println(request.getAttribute("jothi")) gets a call to toString90 method but why the other throws a null pointer??


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Hi Jyothi,


When you first request the jsp file

1. jsp converted to servlet and in service attribute jyothi placed.
2. and in response html form sent.
3. your request ends here.(that means your request,response objects gone).


secondly when user submits the form

1. control reaches servlet
2. tries to find jyothi in request scope.
finally gives up return null.

[ May 11, 2007: Message edited by: Srinivasan thoyyeti ]

Thanks & Regards,<br />T.Srinivasan,<br />SCWCD 1.4(89%),SCJP 5.0(75%)<br />"That service is the noblest which is rendered for its own sake." - Mahatma Gandhi
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14669
    
  11

Try the following :


You are using a java1.5 feature called unboxing, which converts an Integer into an int.
But you are trying to convert null into an int, which fails.
It would work with Integer i = (Integer)request.getAttribute("jothi");

Maybe you'd better use SDK1.4 to practice for this exam.


[My Blog]
All roads lead to JavaRanch
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 8795

Satou,

You are really amazing. No words to praise you man. You point out my mistakes elegantly. Thanks!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 8795

Consider the code as below,



I'm confused as when I run this I'm getting shanar as the o/p. Shouldn't the forward call in includedjsp.jsp ignore anything that we set???

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Request Attribute confusion
 
Similar Threads
Session in JSP
request Attribute doubt?
jsp
request.getAttribute returning null.
Html Input to oracle through servlet and JSP output