File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Scriplets - bad practise, why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Scriplets - bad practise, why?" Watch "Scriplets - bad practise, why?" New topic

Scriplets - bad practise, why?

Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Hi guys,

I have been reading around alot on how to present data on a JSP/html etc.

I was just wondering why do developers consider the use of scriplets to be bad practise? Surely when it comes to say looping/ organising presenting data they're great??

Thanks in advance

Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
no, they're terrible.
Not only do they lead to extremely messy code, that code is also impossible to maintain by people who are not Java programmers.
JSP are meant for maintenance by website authors.

You can do everything you can with scriptlets by using custom tags, and much of what you can do with scriptlets you shouldn't be doing in the first place (like anything that's not purely presentation logic).

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Surely when it comes to say looping/ organising presenting data they're great

People thought the same, at first. Because you can do anything. Anything from good things to bad things, especially bad ones for those who did not use scriptlets properly. I've seen jsp files full of scriptlet. A mess it is. Unreadable. From now on, keep it clean, with tags. There are great too.

[My Blog]
All roads lead to JavaRanch
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Let's not forget about the lack of code reuse.

How the heck do you reuse a chunk of code inside of a scriptlet inside of a JSP. And 'cut and paste' doesn't count.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

And let's not forget about testing.

Well, for code embedded in a JSP, you pretty much need to forget about testng!

At this point in the development of JSP as a technology, scriplets should be considered deprecated in favor of JSTL, EL and custom actions on your pages.

This article touches upon the progress of web application structural patterns.

[Asking smart questions] [About Bear] [Books by Bear]
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Thanks guys,

I see your point re: scriplets.

Bear the article link you posted is awesome, alot to read, but absolutley fab, extremely informative.

I had a quick look at a JSTL tutorial, theres a mighty lot to learn !

I'm considering proceeding with my project as it is JSP/Servlets/Beans, to meet the deadline, and after that might phase in JSTL etc..JSF look nice too.

Thanks once again for the advice,
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

I wont forget some 4000 lines JSPs....
[ August 29, 2006: Message edited by: Oricio Ocle ]

I agree. Here's the link:
subject: Scriplets - bad practise, why?
It's not a secret anymore!