This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP , mysql and mvc ?

 
Rouven Withake
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

http://java.sun.com/blueprints/corej2eepatterns/Patterns/BusinessDelegate.html
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

http://simple.souther.us/SimpleTable.war

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.
 
Adam J Smith
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Head First book is good but if you really want to learn with a great mock database example, use the http://simple.souther.us/SimpleTable.war. I read many many books and articles and none come close to the http://simple.souther.us/SimpleTable.war example. I recommend the SimpleTable example to alot of people.
[ May 08, 2008: Message edited by: Mike Jenkins ]
 
K Sathya Narayanan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mvc is model view controller

model-represents the data.you 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.

HTH
K Sathya Narayanan
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64711
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic