File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes JSP , mysql and mvc ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP , mysql and mvc ?" Watch "JSP , mysql and mvc ?" New topic

JSP , mysql and mvc ?

Rouven Withake

Joined: May 05, 2008
Posts: 4
Hello this is my first post on this board so I hope iam in the right section.
I have done a bit of java before but now Iam doing a web app with jsp and mysql. If I wanted it simple I could just put stuff like the db connection in the jsp file etc. But thats not what I want, I would like to use the mvc model to do this. However I searched quite a bit in this forum and on the internet and could not find a tutorial or code example which combines jsp mysql and mvc.

Basically i just need a code example to start of my app.

All the application should do in the end is enter data over a form into the mysql database , also before entering data it does retrieve some date for 2 drop down menus from the databae.

If anyone has any links to tutorials or could post some example code that would be great.

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Are you having any problems? Where are you at so far? What have you done?

Read up and learn the Business Delegate design pattern. This pattern will help you understand how to build a structure that will connect the Model to the Controller.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

You probably won't find many tutorials because the point of MVC is to decouple your database classes from 'web' tiers of your app.

I have one code sample that I've never polished up enough to publish on my site but there is enough there to show the basic point.

In it, the class that accesses the (mock) database has no javax.servlet.* imports. It can be called from the command line, a swing app, or, in this case, a web app. Likewise, the servlets and JSPs have no java.sql.* imports.
They have no idea that this class is getting its data from a database.
They just know that they can call the object's methods and get back results.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Adam J Smith

Joined: Apr 23, 2008
Posts: 20
If you have access to or wish to buy Head First Servlets and JSP there is an example in Ch 3 that utilizes the MVC pattern from start to finish using a static HTML page to get inputs, a java class that return the results, a servlet that links the two and a JSP page that presents the results. You could replace the POJO in that example with a class or classes that will handle your database connection and return the results you need. I do not know of an example online that will provide everything you are looking for. If anyone else knows of such an example I would be very appreciative.
Rouven Withake

Joined: May 05, 2008
Posts: 4
Thanks for all the answers so far.
As for my web app I have finished the classes for the db connection as well as the various sql strings. I also already have a jsp file which basically is a html file with a form.
All thats missing so far is the servlet.
I will take a look at the book tomorrow a friend of mine has it.
[ May 05, 2008: Message edited by: Rouven Withake ]
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
The Head First book is good but if you really want to learn with a great mock database example, use the I read many many books and articles and none come close to the example. I recommend the SimpleTable example to alot of people.
[ May 08, 2008: Message edited by: Mike Jenkins ]
K Sathya Narayanan

Joined: Feb 15, 2007
Posts: 28
mvc is model view controller

model-represents the can think of this as data base and code which access the database. here mysql and java source which access the mysql becomes the model

view-this represents user intreface, here jsp represents the view.

controller-This mainly deals with business processing. it should be done using a Pogo/servlets but should not be done in jsp. for checking the validity of user , identifying which jsp should be called etc .

MVC is a concept . there are two versions of ,mvc

mvc1 ->all the view,control elements are implemented using Servlets/jsp.
mvc2 -> the view is implemented using JSP,and the controller is implemented using Servlets,as JSP provides better user interface than Servlets.

here MVC deals how the project is organized ,so if you is a project in which all the ui is handled by jsp , other database or other operations like login validation done by servlets/pogo, then it is mvc2. if you see a project in which all the ui and database operation done in jsp , then it is mvc1.

mvc2 is used in IT industry . but when you get more experience in the IT industry mvc will be replaced by design patterns in large projects.

K Sathya Narayanan
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Originally posted by K Sathya Narayanan:
there are two versions of mvc

No, there are not.

Model 1 (not MVC1) is not MVC.

Model 2 is an approximation of MVC.

Please see this JSP FAQ entry for accurate information.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: JSP , mysql and mvc ?
It's not a secret anymore!