Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSP and scriptlets

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

like image 471
M-D Avatar asked Oct 18 '12 05:10

M-D


People also ask

What are scriptlets in JSP?

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 %>

Which syntax is correct for JSP scriptlets?

A scriptlet tag is used to execute java source code in JSP. Syntax is as follows: <% java source code %>

What are scriptlets and explain with example?

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.

What is JSP and syntax?

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.


2 Answers

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.

like image 81
jddsantaella Avatar answered Sep 19 '22 12:09

jddsantaella


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.

like image 26
Abubakkar Avatar answered Sep 20 '22 12:09

Abubakkar