JSP and scriptlets

I know that using scripts is now considered taboo. Its good, and I will agree to the words of Top Star (since I'm currently just new to Java).

What I have heard so far is to make the life of designers easier. But I wonder if this has anything to do with JSP page performance. On the other hand, if it's just to β€œsimplify the creation of designers,” what do you guys think about using scripts in a situation where a Java developer does both?

If scriptlets are bad in every way these days, what are your recommendations? EL? JSTL?

thanks

+6
source share
4 answers

This is not only about making life easier for others, but also making your life easier. JSTL and other tags make / help you write JSP correctly. The problem with scriptlets is that people are doing something in the JSP that they shouldn't. I mean, JSTL (among other tags) helps save the MVC pattern, because basically, if there is something that you cannot do with JSTL in JSP, it is because you shouldn't. If you do not respect MVC and do something in JSP, you should not

You can use JSTL, location tags, spring tags, etc. There are several options, and you can combine them.

+6
source

EL and JSTL are what I recommend because they also make life easier for developers. Your code readability improves with EL and JSTL compared to scripts. With JSTL, I experienced that iterating through an arraylist is so simple compared to using scripts. This is just one that I found so useful. But there are a lot of them.

+1
source

I personally don’t feel that the scriptlets are bad if you perform small checks of conditions, for example, the session is valid, or the user is logged in, etc. And if the Java developer is also a user interface developer, then for small codes, he should be fine. But to do a lot of java things, such as fetching data from a database, checking business rules, etc. Very bad. Although I highly recommend EL and JSTL, scriptlets are suitable for a few lines of code if you do not have time to learn JSTL (for example, project dates, etc.).

0
source

Scripting is definitely not recommended. The main reason is that we handle special cases for NullPointerExceptions , etc. See Head First Servlets and JPS. Expression languages ​​are a refined version of the same, plus the provision of more functions. Always remember, you should always avoid scripting in your JSP.

Using expression languages ​​and JSTL just doesn't keep your code clean, but it also helps developers avoid unnecessary handling over and over.

0
source

Source: https://habr.com/ru/post/927992/


All Articles