JSP and scriptlets
Asked Answered
C

4

6

I know that using scriptlets are considered taboo nowadays. Its okay and I will agree to the Top Star's words (as I am just a novice in Java at the moment).

What I have heard so far is, its to make the designers life easier. But I wonder, if it has anything to do with performance of JSP pages. On the other hand, if its just for "making designers life easier", what do you guys think about using scriptlets in a situation where Java developer do both the work ?

If scriptlets are bad in all aspects nowadays, what are your recommendations ? EL ? JSTL ?

Thanks

Costive answered 18/10, 2012 at 5:23 Comment(1)
Related: #3178233, stackoverflow.com/tags/jsp/info, stackoverflow.com/tags/jstl/info and stackoverflow.com/tags/el/info The latter three could be found by hovering the [jsp], [jstl] and [el] tags which you put on the question and then clicking the info link at the bottom of the black info box.Earwax
F
6

It is not just about making others life easier, it is also about making YOUR life easier. JSTL and other tags force/help you to write a JSP properly. A problem with scriptlets is that people do things in a JSP that they shouldn't. I mean, JSTL (among other tags) helps you to keep MVC pattern because basically, if there is something that you cannot do with JSTL in a JSP, it is because you should not. If you do not respect MVC and do things in JSPs that you shouldn't

You can use JSTL, struts tags, springs tags, etc. There are few options and you can combine them.

Fulltime answered 18/10, 2012 at 6:35 Comment(0)
B
1

EL and JSTL is what I recommend because they make developers life easy too. Your code readability is improved when you use EL and JSTL in comparison to scriplets. With JSTL, I experienced that iterating through an arraylist is so easy in comparison to using scriptlets. This is just one thing that I found so useful. But there are plenty of it.

Briticism answered 18/10, 2012 at 5:27 Comment(2)
Abu, two questions : 1. Are EL and JSTL the same ? 2. Any idea about the performance gains/losses due to scriptlets and these new stuffs ?Costive
EL and JSTL are different but both of them are very useful. I don't know about performance issues.Briticism
A
0

I personally don't feel scriptlets are bad, if you are doing small condition checks like is session valid, or user has logged in etc like that. And if Java developer is also a UI developer then for small codes it should be ok. But doing lot of java things like fetching data from DB, business rules validations etc is a very very bad. Though I strongly recommend EL and JSTL, scriptlets are ok for few lines of code incase you don't have time to learn JSTL (like project deadlines etc)

Ankerite answered 18/10, 2012 at 6:36 Comment(0)
G
0

Scriptlets are definitely something not recommended as of now. The primary reason being handling special cases all over for NullPointerExceptions, etc. Refer: Head First Servlets and JPS. Expression Languages are a refined version of the same, plus providing lot more functionalities. Always remember, you must always avoid scripting in your JSPs.

Using expression languages and JSTLs just not make your code clean, but also help developers avoid unnecessary handling many a times.

Gethsemane answered 25/10, 2012 at 14:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.