• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

problem when trying code from HFSJ

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm just trying code in HFSJ page 346-347 with a little modifications.
my code as per below

Person.java


MyServlet.java


Test.jsp


all above code compiled perfectly but when I run, it throw null pointer exception.
I realized in Person.java, I don't define name variable. Does it the cause of NPE?? but I think it should read the name from MyServlet.java when I call setName method.

What did I miss here? thank you for any reply.

regards,
-Vierda Mila-
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code request.getAttribute ("person") must by itself be returning null. If name were null you would see 'Person is: null' when Person is: <%= p.getName() %> is executed.

Do you have a related stack trace ? You are reaching the JSP through the servlet right ?
 
Vierda Mila
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Deepak,

thanks for your prompt reply and ouch...silly me, yeah I forgot to run the servlet first
will be careful next time

regards,
-Vierda Mila-
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic