• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Converting JSP to servlets

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic