• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

JSP coding /counting standards?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raymond,
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.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
    WS
     
    Bear Bibeault
    Sheriff
    Posts: 67750
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    "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.
    Thanks!
    bear
    JSP Forum Bartender
     
    Let's go to the waterfront with this tiny ad:
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic