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
A JSP scriptlet is used to contain any code fragment that is valid for the scripting language used in a page. The syntax for a scriptlet is as follows: <% scripting-language-statements %>
A scriptlet tag is used to execute java source code in JSP. Syntax is as follows: <% java source code %>
A scriptlet is a piece of software code that is used by a native Web page scripting language to perform a specific function or process. Scriptlets are primarily implemented in JavaServer Pages (JSP) and include variables, expressions or statements that are used only when requested by a certain client or process.
JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With