File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes JSP coding /counting standards? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP coding /counting standards?" Watch "JSP coding /counting standards?" New topic

JSP coding /counting standards?

Raymond O'Leary

Joined: Mar 23, 2004
Posts: 24
hi lads,
Not sure if this is in the correct place......but, I'm just wondering if there are any defined jsp coding and counting standards?
Or should i just stick to a predefined java one?
Would it be difficult to define my own standards?
Is there any rules of thumb I should follow?
Oh and in my code I have SQL statements reading/ writing etc to a database. Is this all done on the database side or in the jsp page?
Having a bit of difficulty finding stuff on the web.
Anyway thanks guys
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

Sun has a document on JSP coding standards. What is a counting standard?
You could use Sun's guide as a reference. It is ok to make variations on it as long as your team agrees.
It is better to keep the database stuff out of the jsp. It can go in a servlet or a javbean.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
of course all that doc is completely out the window once you start using exclusively JSTL.
What I'm writing now there's not a single line of scriptlet code in the JSP, it's JSTL only (which is now the preferred way by many people and I'm trying to get the rest of the team here to adopt).

Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136
You may also want to do some reading on the MVC (Model View Controller) architecture, especially since you are incorporating a database. Sun's site has some pretty good white papers on MVC architecture.

for (int i = today; i < endOfTime; i++) { code(); }
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

Like Jeanne, I have no idea what you mean by 'counting standards'.
And Jeroen and Winston make a good point.
Like Jeroen, I am striving to write my current set of web apps with no Java on the pages. And if you are setting up a properly architected web app using the MVC pattern as Winston suggested, and especially if you are using JSP 2.0, it's surprisingly easy to do so.
Between having a servlet/action controller to perform any processing and to set up data in a manner suitable for the page, the JSTL, the EL (Expression Language), and the ease with which custom actions (formerly known as custom tags) can now be created (using the new, simpler API and tag files), it's nothing short of amazing how compact, simple, readable and easily maintained even complex pages can be without all the Java goo in them.

[Asking smart questions] [About Bear] [Books by Bear]
Liz Brown
Ranch Hand

Joined: Oct 22, 2002
Posts: 112
Hi guys,
When you said the JSp should not be interacting with db directly. I see that i can use sql taglib in JSTL but that is also not recommeneded.
Then how do we deal with db handling in JSP's? I have JavaBeans and EJB's as option. How do JavaBean interact with EJB for db querying. Or is it that i use connection handling in Javabeans directly?
What are the pros and cons of Javabeans with jsp and db?
Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136
What we've been using as a model is as follows:
  • JavaBean controls standard database connectivity (maintains access info such as IP, port, username, etc.); also responsible for opening / closing connections
  • Beans which require database connectivity extend the connectivity class mentioned above, this way, they inherit the ability to open and close connections, and perform any JDBC operations
  • Beans (or Servlets) retrieve data from database, and deliver to JSP page, where it is displayed appropriately

  • This model enforces a good seperation between business logic and presentation, a seperation which, in my opinion, is critical if you're developing any web apps of substantial size. I've had the misfortune of debugging my co-worker's code on several occasions. All of his business logic was contained in the JSP page itself, so you can imagine how large such a page can get -- it became a nightmarish potpurri of SQL queries, result set parsing, and data structure manipulations. The "guts" of the program do not belong in the JSP page. Keep them contained in Servlets or Beans.
    Bear Bibeault
    Author and ninkuma

    Joined: Jan 10, 2002
    Posts: 63873

    "shivan B",
    We're really glad that you are here with us in the JSP forum, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
    In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
    JSP Forum Bartender
    I agree. Here's the link:
    subject: JSP coding /counting standards?
    It's not a secret anymore!