Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTML in Java

 
Ed Carrington
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic