Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

7. Using JSP: Being a JSP > But then Kim mentions “expressions”

But then Kim mentions “expressions”

Just when you thought it was safe, Kim notices the scriptlet with an out.println() statement. This is JSP, folks. Part of the whole point of JSP is to avoid println()! That’s why there’s a JSP expression element—it automatically prints out whatever you put between the tags.

image with no caption

Scriptlet code:

<%@ page import="foo.*" %>
<html>
<body>
The page count is:
<% out.println(Counter.getCount()); %>
</body>
</html>

Expression code:

<%@ page import="foo.*" %>
<html>
<body>
The page count is now:
<%= Counter.getCount() %>
</body>
</html>

Note

The expression is shorter—we don’t need to explicitly do the print...

Notice what’s different between the tag for the scriptlet code and the tag for the expression? The scriptlet code is between angle brackets with percent signs : <% and %>. But the expression adds an additional character to the start of the element—an equals sign (=).


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint