JavaRanch Home    
 
This page:         last edited 16 April 2013         What's Changed?         Edit

Why Not Use Scriptlets   

JSP 2.0 was introduced in 2002 with the JSTL and EL intended to replace Java scriptlets in JSP pages. 2002! Almost 12 years ago! If you are still using scriptlets in JSPs, you are 12 years behind the times.

Java scriptlets have been obsolete and discredited since the introduction of JSP 2.0 and there are many good reasons not to use Java scriptlets in JSPs including:

  • Readability - There are already enough syntaxes in web pages -- HTML, JavaScript and CSS. Using JSTL tags in the view just makes pages easier to read without a lot of Java code jumbled into them. Keep the Java code in Java classes where it belongs.
  • Separation of Concerns - Best practices dictate that presentation logic and business logic should not be mixed.
  • Reusability - How would one use code in a JSP over again in subsequent JSP pages or Java classes?
  • Maintainability - A database column changes and you will be hunting through all your JSPs for places to change. Better to do this in Java classes lets where it can be easily refactored.
  • Scriptlets Break OOP - scriptlets cannot be extended or encapsulated.
  • Getting business logic out of JSPs lets you take advantage of the Java bean paradigm

Due to the above, a developer using scriptlets is a clear warning sign that a developer:

  • Is not serious about their craft
  • Does not know what they are doing
  • Does not care to follow best practices
  • Has not updated their skills in over 10 years
  • All of the above

Do you want this to be you?

This Javaranch Journal article explains the evolution of modern best practices with regards to web application structure.



JspFaq

JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton