I would like some help with my Servlet as I would like my Servlet to run first and to create a session var then forward the value to the JSP (the GUI ) and have the JSP able to send a var back to the Servlet for reprocessing
and update the session var to again be sent to the JSP and so on . - The Servlet contains logic to handle incorrect input types and directly out puts a HTML error page...hope this makes sense!
Below I will add the code I have so far and a link to the question in my Text Book.
The Question is no 7 on this page : Text Book Hope this helps you to understand what i am trying to achieve .
Now its almost right ...for some reason the transactions always seem to be one transaction behind eg. if I start on a 0.00 balance then deposit 100 then it displays 0.00 balance then I deposit 50 it displays a balance of 100.00 then I deposit 10 it shows a balance of 150.00 and so on ....
And the error handling (incorrect input type detection) is not working no matter what.
Actually, I think it is meant to be this way. The textbook examples being followed start with a "bad" way of doing things, and then progressively shows you how to make things better, explaining why along the way.
So the first example (posted in another thread) had everything in the servlet. This step is starting to pull the front end code out into a JSP.
There is still definitely room for improvement in this class though.
A couple of points I think are relevant:
A servlet should either handle the output itself (writing to the response) OR forward via the request dispatcher. It should NEVER do both - suddenly you have two bits of code writing to the response, which probably leads to an Exception.
In general the structure should be something like:
Right now you are displaying your page, and THEN going and running actions (which might result in an error message)
As a generic coding suggestion, there looks to be a lot of repeated/redundant code. I would recommend refactoring it into a displayErrorMessage() method which then makes your code easier to read as it condenses the rest of your logic.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database