aspose file tools
The moose likes JSP and the fly likes JSTL and scriptlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL and scriptlets" Watch "JSTL and scriptlets" New topic

JSTL and scriptlets

Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 185

Hi guys,

I have read in a few places now not to use jsp script in jsp pages. I can see why but every book I go through to learn how to do web programming always has a jsp section with scriplets. It puts me off completely even looking at it to be perfectly honest, it's horrible! JSTL seems to be the work around and far better. I am learning to use servlets now to process html forms and send the data to an output page. I use java classes as my 'backend', a servlet as a 'middle man' and JSTL to show the data on the output page. I'm just curious is this the correct way to go about it or do developers still use scriplets? I am trying to get into my head how its done in the real world. It will help me learn and understand web programming better.

In a nutshell, if you were to write an overview paragraph in a web programming book (for beginners) with the title 'How its done in the real world', what would you say?

J. Kevin Robbins

Joined: Dec 16, 2010
Posts: 1362

In the real world, you'll need to understand scriptlets to support legacy code, and unfortunately, there are still companies writing scriptlet code today (like mine). I'm the heretic here because I refuse to write scriptlets.

Just over a year ago I was working at a shop that had a nightmare of scriptlet code. It was nothing for a jsp to contain over 1000 lines of scriptlet code and embedded javascript. It was a nightmare. Completely unmaintainable. I only worked there for the two months that it took me to find another job.

I've already decided that the next time I'm offered a job, I'll insist on looking at their code-base. If I see a mountain of scriptlets, I will decline the job unless it involves a project to re-design and refactor all that crap code.

You are on the right track with the MVC architecture. That's the way it should be done.

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Harsha Ka
Ranch Hand

Joined: Mar 14, 2010
Posts: 45

More and more companies, who are into core web development have "banished" scripting. But companies which are into "quick-development" web projects sadly still use scriptlets

SCJP 1.6,Preparing (Tryin to prepare) for scwcd
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62830

Any book on JSP would be incomplete without coverage of scriptlets as they are still supported by JSP.

However, as already pointed out, this should only be used when supporting legacy code. All new JSP development -- indeed, for the past 10 years -- should be free of scriptlets.

And I don't buy the "quick development" baloney. It's just as quick to do things correctly as to do them sloppily.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
J. Kevin Robbins

Joined: Dec 16, 2010
Posts: 1362

Bear Bibeault wrote:
And I don't buy the "quick development" baloney. It's just as quick to do things correctly as to do them sloppily.

I'm certainly not defending them, but the pro-scriptlet folks at HQ reason that it's easier to upload a single jsp file, with maybe a css and js file, than to deploy servlets, POJOs, modify web.xml, etc.

What they don't seem to understand is that the time you save on initial development is going to be eaten up by maintenance, and then some. By using scriptlets, they end up with code that is untestable, can't be extended, abstracted, or re-used, and is a nightmare to modify when enhancements are requested. And I won't even address the security issue of having SQL embedded in the jsp.

There has been at least one case where I was asked to modify an existing app and it was such a mess of scriptlets that it was easier for me to completely re-write the thing using MVC rather than try to modify the existing code. By doing so, I now have an app than can be easily modified in the future.

It's like the old saying...."never enough time to do it right, but always time to do it over".

To the OP, welcome to the "real world".
I agree. Here's the link:
subject: JSTL and scriptlets