This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
Joined: Apr 16, 2008
Posts: 2187
posted
0
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.
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.
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
Joined: May 05, 2008
Posts: 4
posted
0
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
posted
0
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
Joined: Feb 15, 2007
Posts: 28
posted
0
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.