• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Quoting and Escape Conventions

 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi can anyone pls tell the reasoning behind the following outputs generated
<%= "<//%Joe said %\\>" %>
output is blank page
but if expression is
<%= "<\\%Joe said %\\>" %>
output is
<\%Joe said %>
for expression
<%= "<\%Joe said" %>
it gives the
org.apache.jasper.JasperException: Unable to compile class for JSPC:\jakarta-tomcat\work\localhost_8080%2Fexamples\_0002fjsp_0002fExpression_00031_0002ejspExpression1_jsp_6.java:58: Invalid escape character.
out.print( "<\%Joe said" );

though API says
A literal <% is quoted by <\%
(Page 40 of jsp 1.2 API)(PDF version)
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The spec section you referred to is for quoting of template text. You are writing a scriptlet, which contains Java code and is subject to the normal Java quoting and escaping conventions.
- Peter
 
Michael Santosa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. <%= "<//%Joe said %\\>" %>
Will be :
<//%Joe said %\> in generated HTML
And remember \\ = \ as in Normal Java.
And <//%Joe said %\> can't be interpreted by
browser so it will display empty
2.
<%= "<\\%Joe said %\\>" %>
Because the same problem \\ = \
Will be :
<\%Joe said %\> in generated HTML
And fortunaly browser is able to interprete
this.. doesn anybody know what is the reason ??
3.
<%= "<\%Joe said" %>
Peter had answered that clearly.
By my question is :
Can we make :
<%= "<% a=a+1; %>" %>
I mean scriptlet in expression ??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic