• Post Reply Bookmark Topic Watch Topic
  • New Topic

Proper way for JSP and MySQL

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After searching this site pretty extensivly I have noticed that whenever someone has a question about JSP and MySQL, everyone seems to be using and giving a solution using a scriplet with JAVA code to connect to the database.
Has anyone used the JSTL/sql library for doing this and been successful?
Is there a "propor" solution be it with a scriplet or jstl/sql? Or is it pure preference?
Thanks
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess when you get into pure preferences, I never access a database from my JSP. I prefer to put that code in a servlet or a bean and access that from the JSP. That seems to be the popular design method that I've seen suggested.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per your preference, then why even use a JSP page. You can access a database through s servlet using straight HTML.
Unless you manipulate the data returned using JSP??
Thanks for the response.
Still looking for people that use the jstl\sql library with success and whether they prefer that method over scriplets or vice versa.
Thanks.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question. My answer is based on the fact that I haven't looked at the JSTL, so it may change after I look at it. I also need to preface this by saying that I am not a JSP expert.
The code in JSP to access a bean is much cleaner than the code to access a database directly. It can be done without placing any pure Java code in the JSP. What I have done in the past, although I'm not sure if it is a good practice, is to use a helper class to add the html tags to the dynamic data and have a page with mostly html for formating and just pull the attribute from the request.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use a Servlet to access a database I just write the servlet to handle all the output, formattting and all. Don't know if that is good practice, but there are only 12 people accessing the database anyway, so speed and resources are definatly not an issue.
I finally got the JSP database access to work using the jstl tags. It's pretty clean, but your db access information does sit in your jsp page directly. So it is hackable. Not too secure.
I just needed to do it to say I did it. I am still learning.
Thanks Matthew.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!