• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException...

 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting a java.lang.NullPointerException and I can't figure out why. Here is the Stack Trace. Its happening at line 63 in my doPost of my servlet..



This is the code...



the problem is in the else statement, I just don't know why my getServletContext() is causing this error...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its the getServletContext() in my else statement.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's your problem:

You override the base init and discard the passed config. So it never gets stored and you get an NPE when you try to access it.

The rules:

1) Don't override init if you don't have anything to do.

2) If you do have somethig to do, override the parameterless init().

See the Servlets FAQ for more info.
[ November 21, 2007: Message edited by: Bear Bibeault ]
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just figured that out and when I came here to post it that is exactly what you had just said. I had started coding my servlet from an example I had found somewhere online, and they had overridden the init(). I didn't have anything to override so I just left it sitting there blank like you would expect of a greenhorn.

I got it to forward on, but when I do the "<p>$(modelBean.Po)</p>" in my jsp it actually prints out "$(modelBean.Po)". Now I assumed that this was some sort of value reference. How exactly do I access my bean data? Or should I, instead of writing a bean, just set a session attribute. I found that doing a session.setAttribute from within my FormManager controller doesn't work. The Simple MVC example uses a bean to control data, so that is what I did to get it working.

My results.jsp page looks like this...



Am I missing something? I just want to see the values and prove that things are working before I go ahead and start to implement more of my logic.

Thanks for the help
Bryce
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EL expressions use curly braces.
${}

not parenthesis
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, my eyes deceived me when I looked at the example code. My font is pretty small and {} looks a lot like (). Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic