The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

stephen.hartley (4) [Avatar] Offline
#1
Second edition, Chapter 11, JSP Advanced Topics, page 192, final example on the page.

The text suggests that the JSP

<% (isUserLoogedIn) %>
Welcome, <%= userName %>!

will translate to the following servlet code:

if (isUserLoggedIn)
out.write("Welcome, ");
out.print(userName);

ie the value of userName is output regardless of the outcome of the 'if', but the "Welcome" is conditional.

However, I am running Tomcat ver 5.0.28 and the generated code is

if (isUserLoggedIn)
out.write("
");
out.write("Welcome, ");
out.print( userName );
out.write("!
");

Hence the output of all of the text is not conditional. The line terminator in the JSP has been interpreted as printable output.

A quick look in the version 2.0 JSP spec does not give an example of this.

Could this be another error in the book? On the other hand, the accompanying text only says that omitting braces might cause undesired behaviour...

Stephen