I'm writing a servlet that gets data from some html and tries to add it to a database. Obviously, the add either succeeds or fails. Once the database update is done, I need to call a JSP to tell the user what happened. Murach's says just use RequestDispatcher.forward(request, response). Makes sense except the request and response are unaware of the results of the database insert. How do I pass that along to the JSP also? ms
It really just depends on what parts of your code need to know about the success or failure of your servlet actions. If you only need to include the results on the JSP, put use request.setAttribute(...). If subsequent calls will also need to know about the transaction result then put it in the session. In general, use the narrowest scope that you can. Most likely, the request object will work fine for you.