Click to See Complete Forum and Search --> : Stops parsing at %> in a string. A bug?


smith.norton
05-25-2006, 08:45 AM
When I access the following JSP page, it runs well.

<html>
<head>
<title>
hello
</title>
<body>
<% out.println("Check this: <% hello > End"); %>
</body>
</html>

When I check the $CATALINA_HOME/localhost/_/org/apache/jsp/exp folder for the java-servlet code, i find the following out.write and out.println statements.

out.write("<head>\r\n");
out.write("<title>\r\n");
out.write("hello\r\n");
out.write("</title>\r\n");
out.write("<body>\r\n");
out.println("Check this: <% hello > End");
out.write("\r\n");
out.write("</body>\r\n");
out.write("</html>");

This is all fine. But when I try to access this JSP page, I get error.

<html>
<head>
<title>
hello
</title>
<body>
<% out.println("Check this: <% hello %> End"); %>
</body>
</html>

The culprit can be found in the following Java-Servlet code.
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write("<title>\r\n");
out.write("hello\r\n");
out.write("</title>\r\n");
out.write("<body>\r\n");
out.println("Check this: <% hello
out.write(" End\"); %>\r\n");
out.write("</body>\r\n");
out.write("</html>");

Am I making a mistake or is it a bug in Tomcat? I am using Tomcat 5.5.6.

Khalid Ali
05-25-2006, 08:50 AM
take a good look at this line
<% out.println("Check this: <% hello %> End"); %>
Do you see anything wrong with the start and end tags?
these tags should be removed from this line, u have a jsp tag inside another tag

smith.norton
05-25-2006, 09:36 AM
A comment in a string isn't a comment.

Similarly a JSP tag within a string shouldn't be considered a JSP tag.

Waylander
05-25-2006, 09:17 PM
Are you trying to print the string to the document?

Perhaps something like this is what your after:


<% out.println("Check this: <:%: hello %:>: End"); %>


Now if you replace the ":" character with the correct ";" that will get you what you want, I cant write it with the proper terminator as the browser calculates the character value and just prints it.

Does anyone know how to print the character code and not the character by the way?

Waylander.