2

I've read many things that say to use JSTL or EL in JSPs.... I'm just curious; does using scriptlets in JSP affect the performance of the page?

RustyTheBoyRobot
  • 5,891
  • 4
  • 36
  • 55
giri
  • 26,773
  • 63
  • 143
  • 176

3 Answers3

3

The general advice to use JSTL and EL instead of scriptlets has absolutely nothing to do with performance; if anything, scriptlets are likely to yield better performance.

But they also lead to "tag soup" that is hard to maintain. You're supposed to use JSTL/EL because JSPs are supposed to be a presentation layer and not contain significant logic.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
2

First, using scriptlets (embedding raw Java code in JSP using the old fashioned <% %> things) is not the same as using taglibs (e.g. JSTL) and EL (the ${} things).

The performance penalty of taglibs and EL is really negligible and only noticeable during compilation and does by far not outweigh the advantages of using taglibs and EL instead of scriptlets.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I suspect you completely misunderstood the question. It sounds like he understands perfectly what scriptlets are and just wonders whether the advice against using them and using JSTL and EL is because the latter are *better* for performance... – Michael Borgwardt Jan 24 '10 at 17:55
  • It *sounds like*, yes ;) Just let's see what the OP says instead of throwing with heavy words :) – BalusC Jan 24 '10 at 19:00
0

All JSP taglibs and scriptlets get compiled to a Java class before execution, so there's virtually no performance difference for using one or the other.

Kaleb Brasee
  • 51,193
  • 8
  • 108
  • 113
  • 2
    not exactly true - using scriptlets will probably lead to a slightly shorter call chain than using tags, since scriptlet is basically java source that gets compiled into your jsp, while tags goes thru another layer of indirection. tho negligible, if it can even be observed in practice. – Chii Jan 26 '10 at 07:07
  • Layers of custom tags are slow. If snappy performance in complex pages is an issue, you'll probably want to move view rendering to old-style tags or even Java code. – Thomas W May 09 '13 at 02:50