This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Request Attribute confusion  RSS feed

 
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou,

You are really amazing. No words to praise you man. You point out my mistakes elegantly. Thanks!
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!