Hi!
I currently prefer the following:
* encapsulate JDBC in some kind of beans or persistence layer. Do not spread SQL
statements all over your application. Do not embed SQL in JSP, even if some
taglib vendors offer that as feature.
* place your servlet independent application logic in your beans or business
objects.
* use a servlet or a logic JSP (no displaying here) to interprete the data you
receive from forms. do whatever you need to do with your database etc. here.
Place the objects you want to display in the request, the session or the
servletcontext, so that it is accessible from a display JSP. Then forward the
request to a display JSP appropriate for displaying whatever you need to display.
I.e. there is a 1:n relation between servlet/logic-JSP and display-JSP. There
shouldn't be a lot of code in the servlet. It should merely be used to call
methods of other servlet independent objects. Only the servlet specific code has
to be placed here.
* display your stuff with a display JSP. As you put your objects in the request (or
session, etc.). you can access them via <jsp:usebean>. In your display JSP make
sure you have no or close to no scriptlets. Use a taglib for iteration and
conditional execution (e.g. <customtag:foreach> and <customtag:if>). Write more
custom tags for other special display tasks. Do not write tags for stuff related
to application logic. Do not write too many tags.
Why? If you follow the proposed way, you have a chance of achieving the following
goals:
* separate your application from the web interface (no app logic in the servlet,
just the glue between the web and your app goes here, instead place the applogic
in your app beans or business objects)
* the glue/servlet code and the app code can be written and maintained by real
programmers, not HTML guys (no offense, HTML guys, it is really difficult to do
HTML and Java, but most people do only know to do either one really well)
* the display JSP can be written and maintained by HTML guys who learn some extra
stuff like iteration with custom tags and JSP expressions (e.g.
<%=person.getName()%>)
* JDBC is hidden, so not everybody has to know everything about the underlying
tables and has to be an expert in how to efficiently do joins etc. Also you can
reuse PreparedStatements (*in theory* that gives you a performance boost) and
don't have to deal with SQL all that much
Well, even if you don't follow 'the proposed way' you have a chance to achieve these
goals :-)
This is just my opinion about the whole thing if you want to do it with JSP/Servlets.
It is certainly not the only way to go. Also there are still EJB and XML/XSL(T) and
...
cheers,
-hendrik
- - - - - - - - - - - - - - - - - - - - - - - - - - -
tagtraum industries http://www.tagtraum.com/
jo! small&smart 2.2 servletengine
Java Server & Servlets The web-application book
The WebApp Framework http://www.webapp.de/
Thang Nguyen wrote:
> Hi,
>
> I have this fundalmental question. I hope you can shed some lights for me. I am
> looking to see what would be a common solution to my application.
>
> My project is a web based application which will retrieve values from the informix
> database, manupulate them, and send the results back to the requestors. As far as
> I understand, and was able to run a few examples, I noticed these:
>
> (1) JSP can use JDBC to communicate with database directly
> (2) Servlet can use JDBC to communicate with database directly
> (3) Service Beans can use JDBC to communicate with database directly
> (4) JSP can call Servlet as well as Java Bean
>
> So, what should I use, since the scope of this project can be larger? I am
> looking for these qualities: fast, easy to maintain, and simple.
>
> (1) just use JSP only, use HTML like tag for visual, and JDBDC directly
> for accessing database?
>
> or
> (2) use JSP and Servlets, use HTML like tag for visual, and Servlets (jdbc
> embeded) for accessing database?
>
> or
> (3) use JSP with Java Beans, use Visual Bean for visual and Service Bean
> (jdbc embeded) for accessing database.?
>
> Please help. Thank you very much for your time.
>
> TN
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets