Monday, March 2, 2009

JasperException: Attribute value is quoted with which must be escaped when used within the value

Caused by: org.apache.jasper.JasperException: /web/jsp/view.jsp(204,42) Attribute value pageContext.getAttribute("name").toString() is quoted with " which must be escaped when used within the value

org.apache.jasper.JasperException: /web/jsp/view.jsp(204,42) Attribute value pageContext.getAttribute("name").toString() is quoted with " which must be escaped when used within the value>org.apache.jasper.JasperException: /web/jsp/view.jsp(204,42) Attribute value pageContext.getAttribute("name").toString() is quoted with " which must be escaped when used within the value
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)

PROBLEM:
<a href="
<portlet:param name="node" value="<%=pageContext.getAttribute(\"parent_var\");%>"/>
">..</a>

https://issues.apache.org/bugzilla/show_bug.cgi?id=45015
==========
According to JSP 2.0 specification (chapter 1.7 page 72,73)

This code is illegal:
<mytags:tag value="<%= "hi!" %>" />

Instead the correct sentence would be:
<mytags:tag value='<%= "hi!" %>' />
<mytags:tag value="<%= \"hi!\" %>" />
<mytags:tag value='<%= \"name\" %>' />
==========

SOLUTION:
<a href="
<portlet:param name="node" value='<%=pageContext.getAttribute(\"parent_var\");%>'/>
">..</a>

MORE:
Можно также вывести значение атрибута на консоль
<a href="
<%System.out.println("EEEEEEEE = " + pageContext.getAttribute("parent_var")); %>
<portlet:param name="node" value='<%=pageContext.getAttribute(\"parent_var\");%>'/>
">..</a>

6 comments:

Anonymous said...

very useful! it resolved my issue... almost the same problem.

Kohomba123 said...

Useful post. Solved my problem...Thanks for posting...

Anonymous said...

I'm Russian to by the way.
What if you have application with 1000 jsp pages?
Would you go through every page?
Here is the fix
Set CATALINA_OPTS parameter to ignore quoting
CATALINA_OPTS="-Xmx500m -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false"

Drakmail said...

thanks, man! But in my Ubuntu 9.10 I don seen CATALINA_OPTS variable. As I can see, I can use JAVA_OPTS instead it.

ozgun said...

In the file Tomcat 5.5\conf\catalina.properties I simply added this line:

org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false

To get rid of the jasper double quotes error.

Anonymous said...

A huge thanks for this tip. THe problem had brought me to a complete standstill for about a week (I'm not kidding) and five minutes after reading this, I'm up and running again. Keep up the good work.

Iain