• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP to database - best practice

 
Keri Mathis
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear with me - I last worked with servlets/jsps in 2003. I recently inherited an application that uses all JSPs with JSTL, no servlet. All SQL is done with the JSTL tags, and we are seeing connection/deadlock errors. After trying to troubleshoot the issue, all signs point to "rewrite the database stuff using beans - don't use JSTL sql tags in production."

My problem is I can't find out how to exactly do that. I know how to use JavaBeans with JSP pages, but I don't know how to use them for database interaction. Based on this website, I ordered the highly recommended book "Head First Servlets & JSP 2nd Edition," and I have to say I'm highly disappointed and frustrated that I spent 40 bucks and waited a week for shipping to find out that it doesn't address the database at all. It even admits most JSP/Servlet applications work with a database, but it does not address how to do so. In fact, it barely mentions using beans at all. (Maybe it's my own fault; I was leery that the title geared it to the exam, but everyone said it was a great resourse book as well. But how an 800 page book on Servlets/JSP does not even cover one simple web app end-to-end is beyond me. Thank you for letting me vent, I'm better now.)

So I've been searching forums and Java sites, but cannot find anything that explains in any amount of detail the best way to update my database with JSP form data. If I had two weeks, I'd convert the application to Grails. But for now, I just need to solve the database errors we are getting in the quickest way possible, while adhering to good Java practices.

The official J2EE tutorial uses Java Persistence API, which looks similar to Hibernate. I have not used either outside of a small Grails app, and we have no long-term plans to create more JSP applications and there are time constraints. So I'll learn it if it's the best way, but want to be sure I'm spending my time wisely.

If anyone can point me to some good resources on using JSP with a database (MySql in this case), I'd be very grateful.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Few JSP/Servlets books will address the database as that's something usually well-sequestered away from the UI layer. So you're disappointment with the book you chose would be true for almost any book on JSP and Servlets.

Apparently whoever set up this app initially did not heed the warning in the JSTL Specification itself that warns against using the JSTL SQL tags for anything other than quick prototypes.

In a nutshell, JSPs should never submit to other JSPs, but always to servlet task controllers that in turn communicate with the business layer. All DB code should be completely hidden by this layer. The DAO pattern is popular for that.

If you only have a short time, learning JPA/Hibernate from scratch may be well out of the question, and raw JDBC may be the way to go if you already have a handle on that.

In any case, perhaps this article might be of help with the high-level organization issues.
 
Keri Mathis
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thanks. I can set up a servlet/dao layer base on previous Java applications I've worked with, just thought there may be some better way with the JSP pages I was unaware of. Thanks for the info and the article link.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure, and welcome to the Ranch!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!