It's not a secret anymore!
The moose likes JSP and the fly likes HTML in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "HTML in Java" Watch "HTML in Java" New topic

HTML in Java

Ed Carrington
Ranch Hand

Joined: Oct 11, 2007
Posts: 77
I sometimes put HTML in my Java helper classes in my Tomcat 4.1.27 container.

I read this is not considered good practice to have HTML in a Java class.
Please advise is it because of a maintenance issue or why?

If I dont put HTML in Java classes then I would have to for example put Java for loops in JSP Scriptlets to output HTML stuff such as links.

I have restrictions where I cant upgrade or use JSTL at this time.
[ December 19, 2007: Message edited by: Ed Carrington ]
Ali Khalfan
Ranch Hand

Joined: Nov 03, 2007
Posts: 126
The main idea is to separate the view from any business logic. It will be easier to reuse the code, and better for maintenance. It won't be easy to read html written in java code that's all. Scriplets in JSP might be a bit easier to use, but the same problem is encountered.

Don't know what restriction you could have for not using JSTL, but using EL is much better for you to distinguish between html and java code.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

Originally posted by Ed Carrington:
I have restrictions where I cant upgrade or use JSTL at this time.

My condolences. Welcome to 2001.

Tomcat 4 is two revs out-of-date at this time. Surely your pointy-haired boss can be convinced to upgrade to at least Tomcat 5?

In any case, almost every tutorial on JSP will show you how to use scriptlets on the pages. Using scriptlets is a much better tactic than putting HTML in Java. At least it's a step towards using JSTL/EL on the pages,
[ December 19, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: HTML in Java
jQuery in Action, 3rd edition