Val, > > I seem to recall reading on one of the user lists (maybe this one) that > using taglibs for connecting to the database was not a good idea, for > security reasons. The consensus was that it was at least better than > embedding Java scrptlets in your JSP. >
The main reason accessing a database through tags is better than Java scriptlets is that the code is simpler and cleaner. From an architecture/design point of view, both approaches can be considered equivalent. The main reason NOT to access a database in the JSPs is separating business logic from presentation, given that you consider JSPs as presentation only technology (strange as it may seem, not everybody does!). And Model 2 is one approach to that, the most popular one, but not necessarily the best. > My question/plea for input here is regarding what I should be using to > write > the actual connection in. If tags are not recommended, then should I be > using a class, a bean, or a servlet to do that work? I read recently > (I've > been doing a LOT of reading) that tags are a replacement for beans--though > that sort of conflicts with the point that I read before that tags are > only > one step up from using scriptlets. I'm starting to conclude that I should > be using a servlet, but I would really appreciate some confirmation from > people who are experienced with all this. > First, tags are not a replacement for beans, I wonder where you read that ;) Tags are means for providing abstractions/encapsulating functionality, be it business logic or presentation related, that is accessible through an XML-based syntax in a JSP page. That's pretty much all tags are. If you want to separate presentation from the business logic, the first thing you should do is encapsulate the business logic in Java beans. Those Java beans will work with the database to access/store/update/delete data. And the JSPs will use those Java beans to get the information to display. When it comes to getting input from the end-user and storing it in the database, you will need to somehow set the bean properties from a submitted HTML form and tell the bean to write its information to the database (e.g. something like mybean.insert() or mybean.update). Again, the Java bean deals with database access and your presentation layer deals only with the Java bean. Most JSP/Servlets frameworks map submitted form fields to bean properties automatically. Struts (the most popular Model 2 framework) does that, even though it limits the types of your bean properties to primitive Java types. Our product TICL does it also. All this is pretty much standard practice... > > Also, is it possible/necessary to try to make the structure of the Web > application object oriented? If I'm using JSP, does that negate the need > for creating an object oriented design--does it make that kind of a > design, > even though I'm using Java, impossible to really do? > It is possible and good practice to have your web application be object-oriented. However, JSPs make that very difficult, because they can't be sub-classed. By encapsulating the business logic of your application in Java beans, you have at least that be object-oriented. The presentation logic can be made object-oriented, or close to, by using one of the available UI frameworks. Cheers, Boris ____________________________________________ Borislav Iordanov Chief Architect TICL - a RAD toolkit for server-side Java http://www.kobrix.com > -----Original Message----- > From: A mailing list about Java Server Pages specification and reference > [mailto:JSP-INTEREST@;JAVA.SUN.COM] On Behalf Of rvt > Sent: Friday, October 18, 2002 11:25 AM > To: [EMAIL PROTECTED] > Subject: Database Access Using Tags > > Hi, > I've been scouring the Net trying to figure out the best way to get a > database connection. I'm using JSPs for the view, but I want to keep as > much Java code out of the pages as possible, since that results in a much > cleaner and easier to maintain application. But I'm a newbie when it > comes > to model 2. I've written a site before using just JSP with Dreamweaver > UD4. > But with what I'm working on now, that is not good enough. > > I've got Tomcat set up, and I'm trying to use connection pooling. I know > that I can use JNDI and Tomcat to look after the connection pooling > details, > though I'm tearing my hair out trying to figure out how it all works and > if > I've got all the pieces in place that I need. > > My question/plea for input here is regarding what I should be using to > write > the actual connection in. If tags are not recommended, then should I be > using a class, a bean, or a servlet to do that work? I read recently > (I've > been doing a LOT of reading) that tags are a replacement for beans--though > that sort of conflicts with the point that I read before that tags are > only > one step up from using scriptlets. I'm starting to conclude that I should > be using a servlet, but I would really appreciate some confirmation from > people who are experienced with all this. > > Also, is it possible/necessary to try to make the structure of the Web > application object oriented? If I'm using JSP, does that negate the need > for creating an object oriented design--does it make that kind of a > design, > even though I'm using Java, impossible to really do? > > Thank you for any input. I'm trying to get all these concepts straight in > my head, and the information out there is not only conflicting, but a > little > overwhelming. > > Val > > ======================================================================== == > = > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP- > INTEREST". > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST > DIGEST". > Some relevant FAQs on JSP/Servlets can be found at: > > http://archives.java.sun.com/jsp-interest.html > http://java.sun.com/products/jsp/faq.html > http://www.esperanto.org.nz/jsp/jspfaq.jsp > http://www.jguru.com/faq/index.jsp > http://www.jspinsider.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com