jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Converting JSP to servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Converting JSP to servlets" Watch "Converting JSP to servlets" New topic

Converting JSP to servlets

Tom Joiner
Ranch Hand

Joined: Sep 19, 2006
Posts: 47
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?

Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

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.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
I agree. Here's the link: http://aspose.com/file-tools
subject: Converting JSP to servlets
jQuery in Action, 3rd edition