my dog learned polymorphism
The moose likes Servlets and the fly likes JSP Coding Conventions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP Coding Conventions" Watch "JSP Coding Conventions" New topic

JSP Coding Conventions

Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
I'm just looking for some general rules here.
Is there a standard place to put JSP scriptlets
in the page?
For example do people generally put these at the top
of the page and then the put the HTML below?
Since the JSP is pre preprocessed I figure it doesn't
really matter where you put the scriptlets, but I would
like to follow the standard procedure, right?
Any other tips on the subject appreciated!
ernest fakudze
Ranch Hand

Joined: Aug 27, 2001
Posts: 216
I personally think that it's best to put the jsp code at the top and the HTML below. Reason is: if you start outputing HTML and then try to do a jsp:forward after that, you will get an error saying sth. like 'You are trying to clear a buffer that's already been cleared'. I am fairly new to jsp and I had this problem for weeks until a kind friend of mine told me to re-structure my code by doing all my java code at the top and then the html part at the bottom. I have been happy since .
Also, you should follow the Java Coding Conventions when writing any Java code, including scriplets. It makes your code easier to read by somebody else. The conventions are somewhere on the Sun Website.
[This message has been edited by ernest fakudze (edited October 05, 2001).]

In a time of drastic change it is the learners who inherit the future. The learned usually find themselves equipped to live in a world that no longer exists.<br />Eric Hoffer
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
Of course, if you use a Model-II architecture which puts all of the logic that could POSSIBLY do a forward() (or throw an exception, or any of the other things that make coding JSP's difficult) into a Servlet that you call first, which then populates the session and/or request with JavaBeans that the JSP will display using <jsp:useBean> tags, then everything becomes MUCH simpler.
You can refer to my book for examples of doing Model-II (MVC) coding, or I would also refer you to the Struts framework ( which enforces Model-II and also automates a lot of the grunt work of coding servlets.
Kyle Brown
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at for other WebSphere information.

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
I agree. Here's the link:
subject: JSP Coding Conventions
jQuery in Action, 3rd edition