I want to convert my JSP page to servlets. I will outline the JSP code I wish to convert, and then propose some suggestions.
Here is what the code does:
- Checks to see if this is a fresh page load, or a repost - If it is a repost, checks to see if the account to be created is valid (performs database check to see if the account already exists) - If it is valid, creates the account with a database insert call and redirects the page to a welcome page - If it is not valid, or if it is a fresh page load, draw the page itself which consists of a form
So now I would ask: - How would you break it into servlets? - Would each database query be in its own servlet? - Would you put the drawing of the html into the servlet as well? Into a different servlet?
Actually a jsp is a servlet by itself. What you could do is... get the form parameters from the JSP, call a servlet, control the flow based on business logic written in seperate java files and then hit the DB using some JDBC helper classes (written by you of course ). The logic to check if it is a repost can be incorporated into your servlet. For example you could probably set a flag saying you already got a request from this client in a cookie. If the client requests the servlets resource again, get the cookie and check for this flag. Or you could hit the DB and find out if a record was created for this client. The solution lies based on what screen flow you would like.