[ Team LiB ] Previous Section Next Section

Q&A

Q1:

Why do I need the expression language, isn't Java good enough?

A1:

JSP EL provides a more compact syntax than using scriptlets. It is much more convenient to use the ${} syntax and its powerful . and [] operators than it is to use <% %> and the more cumbersome property access methods. Also, JSP EL always works the same way, regardless of the scripting language you use with JSP. Remember, although JSPs are usually written in Java, you can also find JSP containers that support other scripting language. JSP EL remains the same regardless of the scripting language.

Q2:

When do I use . and when do I use []?

A2:

Although you can use these operators interchangeably, it is a good idea to use an operator that indicates the kind of data being accessed. For example, if you are accessing a bean property, use the . operator. If you are accessing a map value or an array index, use the [] operator. There are plenty of times when you break this rule, especially in cases where you want a map to look like it is a bean, you want things to make sense to the next person who reads your code. You may know the types of all the variables, but the next person may not.


    [ Team LiB ] Previous Section Next Section