File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP Coding Conventions" Watch "JSP Coding Conventions" New topic
Author

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!
Thanks!
Drew
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
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
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 (http://jakarta.apache.org/struts) 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 http://members.aol.com/kgb1001001 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 http://www.kyle-brown.com/ for other WebSphere information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Coding Conventions
 
Similar Threads
value for useBean class is invalid
HTML in tag and Java in JSP
Question about jsp:attribute body
Can I create a drop down menu from an enum
display the log/output in JSP or HTML page