This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Servlets and the fly likes servlet/jsp question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet/jsp question" Watch "servlet/jsp question" New topic
Author

servlet/jsp question

John Gregory
Ranch Hand

Joined: Oct 05, 2006
Posts: 115
I have a jsp page that has certain user info on it and widgets for things they are allowed to
change (pull downs, check boxes ...etc). On the bottom of the page, I have a submit button
which forwards everything to a servlet for processing. The servlet is responsible for doing the
updates, which I have numerous logging statements, with no problem. After I update the user,
I set an attribute and display the updated user info back via another jsp.

Now, the problem comes when I hit the browser back button. It shows the changes I selected
for the particular user. However, if I hit the submit button again, a NullPointerException, presumably
because the change I wished to incorporate has already been done.

Is there anything I do to mitigate this?

Thanks,

John
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
John Gregory wrote:presumably
because the change I wished to incorporate has already been done.
Presumably?

Read the stacktrace, find the root cause in your code and fix it accordingly.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The servlet is responsible for doing the updates, which I have numerous logging statements, with no problem


You can code the update logic so that duplicate submissions will not be processed, i.e. make the "change". This will get rid of the "presumed" NullPointerException.
John Gregory
Ranch Hand

Joined: Oct 05, 2006
Posts: 115
James,

I've done a bit of reading. Are you talking about through session management?

John
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Do you know when a NPE will occur?
Do you know how to fix it?
John Gregory
Ranch Hand

Joined: Oct 05, 2006
Posts: 115
Bauke,

Yes, I know when the NPE will occur -- After I update a user, if I hit the browser back button,
it displays old data, the stuff they had BEFORE I did the update. So that if I hit the Update
button on that page to update them, I get the dreaded NPE.

As to how to fix it, that's not quite so obvious. I've tried mucking with the session attribute,
but haven't gotten it to behave as I want to there. I'm thinking of having an error page that
takes you back the main page to start over again if I find an error. I thought I remembered
seeing that you can do this with http status codes, but don't remember if you can do it with
an exception...have to check again on that.

John
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
There are 2 ways to fix it:
1) instantiate the object reference in question.
2) bypass the access to the object reference in question and if necessary conditionally display an error/warning message.
 
GeeCON Prague 2014
 
subject: servlet/jsp question