This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP database application setup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP database application setup" Watch "JSP database application setup" New topic
Author

JSP database application setup

Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
I am developing a JSP application that queries a database and moves thru result set. Right now I have a class that builds all the input boxes of database fields (so they can me modified), the same class handles database query and sets value parameter of input box with returned data. With this setup one class does everything: builds the screen and populates it each time database is queried. So if a user hits search, screen is build. Hits next, screen is build again from scratch. Should I keep this setup or create another class that just handles database stuff and updates the fields using JavaScript (document.form.field1.value=<%=data%> ? Is this method better? Or should stay from merging JavaScript and JSP on database queries?
thanks a lot for your input,
Alex


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

I wouldn't use Javascript at all for something like this. Nor would have all these levels of functionality in a single class.
For even my most simple web applications, I always follow an MVC-patterned layering in which the "model" exports the data in a completely UI-agnostic manner. I then use servlets to control the actions of the web app, and JSPs with template text to render the web UI.
Some might argue that for small apps that this is "too much work", but I have always found that the investment pays for itself time and time again (and once you get used to doing it this way, it frankly isn't a whole lot of extra work -- it's more in the organization than in the amount of code).
[ April 07, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
thanks.
Do you have any documentation I can look at to learn more?
Gert Cuppens
Ranch Hand

Joined: Jul 13, 2003
Posts: 87
I totally agree with the idea that following the MVC is a time saver when you look at your web application during a longer period.
And one of the books that helped me working my way through the MVC, servlets, beans and JSP's is "core servlets and JavaServer Pages" from Marty Hall. Mary Hall also has a website where you can take a look and even download the pdf-file of the first version of his book : http://www.coreservlets.com.
Another very good book, contaning a full web application built in MVC style, is "Apache Tomcat Bible" (Jon Eaves, Rupert Jones and Warner Godfrey). This book even explains how to install Tomcat, Mysql and other stuff to help you build a Java Web Application.
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
thanks Gert,
In online version of Marty's book, which part discusses MVC?
thanks,
Alex
Gert Cuppens
Ranch Hand

Joined: Jul 13, 2003
Posts: 87
I'm afraid I have to disappoint you, Alex.
Marty Hall does not speak about the Model-View-Controller in his book.
The reason why I think Hall's book is very good, is that he describes in detail the working of servlets and JSP's. And I still get a lot of tricks out of his book.
But if you want to know more about the MVC, then there is the "Apache Tomcat Bible" from Eaves, Jones & Godfrey (Wiley Publishing, Inc).
This book has the advantage that it not only explains the theory behind the MVC. But you can as well build a whole web application, based on the MVC. The source code of this web application can be downloaded at http://www.wiley.com/legacy/compbooks/eaves/.
Where Marty Hall is very good at explaining the details and tricks of servlets and JSP's, this book is an essential one for every one who wants to build web applications with Java, Tomcat and MySQL.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP database application setup