Hello,
I am using a JSP with a <FORM ACTION=Servlet METHOD="POST"> and the Servlet as the controller.
I am also setting a session variable in the JSP as an identifier for the Servlet to identify what action to perform.
ie:
JSP1:
<%session.setAttribute("webAction","someAction")%>
JSP2:
<%session.setAttribute("webAction","someOtherAction")%>
Servlet:
String webAction = (String)session.getAttribute("webAction");
if (webAction.equalsIgnoreCase("someAction")) {
request.getParameter("someParm");
...
} else if (webAction.equalsIgnoreCase("someOtherAction")) {
request.getParameter("someOtherParm");
...
This works great however, if the user hits the back button, I get an nullpointer exception.
I suspect this is because the session attribute has been set by the new JSP they're on and going back results in the servlet processing being called again however this time with the new session attribute where none of the request parameters being set.
What would be the best way to handle this?
Should I test the first paramter obtained for a null value or catch the whole exception?
Or should I be looking at this differently all together?
Any direction appreciated.