13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

428Chapter 19JSP: Servlets Turned Inside OutNotice how the if-else c<strong>on</strong>struct is broken up into three separatescriptlets—that is, snippets of code. Between them, in the body of the if andthe else, is plain HTML. Here is what that will get translated into after theJSP c<strong>on</strong>versi<strong>on</strong>:if (acct != null) { // acct.getParent()out.println("");out.println("");out.println("");} else {out.println("");}Do you also see why we describe it as being “turned inside out”? Whatwas delimited becomes undelimited; what was straight HTML becomesdelimited strings in output statements.As l<strong>on</strong>g as we’re <strong>on</strong> the topic of c<strong>on</strong>versi<strong>on</strong>, let’s c<strong>on</strong>sider comments.There are two ways to write comments in JSP, either in HTML or in Java. InHTML we would write:but since we can put Java inside of delimiters, we can use Java comments, too:or even:If you’ve been following what we’ve been saying about translati<strong>on</strong> of JSPinto Java code, you may have figured out the difference. The Java comments,when compiled, will be removed, as all comments are, from the final executable.The HTML-based comments, however, will be part of the final HTMLoutput. This means that you’ll see the HTML comments in the HTML thatreaches the browser. (Use the View Source command in your browser to seethem. As HTML comments, they aren’t displayed <strong>on</strong> the page, but they aresent to the browser.) This is especially something to be aware of when writinga loop. Remember our loop for generating the table?

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!