aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP output with lessthan % symbol ? - Mika's mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP output with lessthan % symbol ? - Mika Watch "JSP output with lessthan % symbol ? - Mika New topic
Author

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

Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
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


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Srini Admala
Ranch Hand

Joined: Dec 04, 2001
Posts: 50
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

Joined: Jun 03, 2000
Posts: 5040
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

Joined: Dec 15, 2001
Posts: 7
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

Joined: Mar 17, 2000
Posts: 5782
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

Joined: Jun 03, 2000
Posts: 5040
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
 
subject: JSP output with lessthan % symbol ? - Mika's mock
 
Similar Threads
Mock exam question doubt?
Mock exam question doubt?
f:convertDateTIme problem
Mock exam question doubt?
no working