File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP output with lessthan % symbol ? - Mika's mock

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the output of the servlet code below assuming that the surrounding code would be valid?
out.println("<%=new date()%>");

The answer is:
<%=new date()%>
is printed.
I was thinking there should be a backslash between <% and %> to escape the sequence.....
Am I missing something?
Thanks.
- satya
 
Srini Admala
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are right Satya!
It throws a compilation error saying :
String not terminated at end of line.
out.println("<%=new date()
Need a / between % and > at the end for successful compilation :
out.println("<%=new date()%/>");
Even that prints : <%=new date()%/>
Any idea how to print : <%=new date()%> ?
-Srini
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea how to print : <%=new date()%> ?

I think I read somewhere in the Specs that you need to escape it. So I am assuming that
out.print("<\%=new date()%\>")
would work. I haven't tried it yet.
regds.
- satya
 
Mika Hirvasoja
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for pointing that out, it is a bit ambiguous.
'String not terminated at end of line.
out.println("<%=new date()' is the result when the code is used in a JSP page.
However in a Servlet the output is: <%=new date()%> as '<' and '%' are not special characters in Servlets in the same sense as in JSP.
The abovementioned was tested Tomcat 4.0. Do you have other experiences with the output? In what environment are you testing this?
 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Madhav Lakkapragada:
Any idea how to print : <%=new date()%> ?


<%=new date()%> should do the job. The spec says the output of the expression will be converted to a String and included in the response.
Am I missing something :roll:
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as '<' and '%' are not special characters in Servlets in the same sense as in JSP
aha! So this is okay in Servlets and not in JSP.
Thanks.
Ajith:
Pl. check with Mika's post above.
I haven't tried it yet, I am using Tomcat 4.0.1
regds.
- satya
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic