Forums Register Login

JSP , mysql and mvc ?

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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.
Did you miss me? Did you miss this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4745 times.
Similar Threads
Problem deploying MVC with Tomcat
connecting JDBC in wsad to MYSQL
Removing business logic???
Jumping Problem
Picking the right tools for web mobile project
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:23:09.