Learn Java for Web Development

(Tina Meador) #1

122 CHAPTER 3: Best Practices in Java EE Web Development


26.<jsp:useBean id="bookAttrib" class="com.apress.chapter03.model.Book"
27.scope="request" />
28.
29.Author's Name using jsp:getProperty action
30.
31.
32.


33.
34.
35.
36.
37.
38.
39.
${fn:escapeXml("<jsp:getProperty name = \"bookAttrib \" property= \"author \" />")}
${fn:escapeXml("<jsp:getProperty name = \"bookAttrib \" property= \"author.name \" />")}

40.
41.
42.
43.
44.
45.
47.
48.
49.
53.
54.

46.

50.<%-- - this code will yield run time
exception --%>
51.Not possible
52.

55.
56.
57.
58.Author's Name using EL
59.${fn:escapeXml("${bookAttrib.author.name}")}
60.${bookAttrib.author.name}
61.
62.
63.
64.


   Line 23: This outputs the name of the author using expressions.
 Line 50: This shows that it is not possible to output the name of the author using
a JSP standard action.
 Line 60: This outputs the name of the author using EL.

Figure 3-7 illustrates what you will see when you run this application (http://localhost:8080/
chapter03/book). Essentially, it is just not possible to display the value of the name property of Author
using a standard JSP action; scripting elements would have been the only way to do it, had it not
been for EL.

Free download pdf