Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP error because of a qouted value insied a qoute.

 
victor chiong
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Tomcat will not allow this because of error:

org.apache.jasper.JasperException: /TestBean.jsp(20,10) Attribute value request.getParameter('userName') is quoted with ' which must be escaped when used within the value
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)



<code=jsp>

<jsp:setProperty name="person" property="name"
value="<%= request.getParameter("userName")%>" />

</code>

Any ideas? I found a solution but i could not understand it...

For tomcat, this is the reason.... Where to find that settings in tomcat Catalina?

STRICT_QUOTE_ESCAPING as true where as

6.0.20 treats STRICT_QUOTE_ESCAPING as false.




regards,
Vic
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a Tomcat problem.

You are, in effect, coding a string in the form of "this is "a" string" and the inner quotes are causing the lexical scanner to become confused because there's no unambiguous way to know that they are inner quotes instead of terminal quotes. As in "this is" + a + "string".

You need to disambiguate the text, and you should be able to do that using escapes. In Java, that would be "this is \"a\" string".
 
victor chiong
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

This is what you mean?

value="<%= request.getParameter(\"userName\")%>" /> ?
 
Paul Clapham
Sheriff
Pie
Posts: 20170
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP is like HTML. (But you knew that already, right?)

In particular JSP is like HTML in that you can use either the quote character (") or the apostrophe character (') to delimit attribute values.
 
victor chiong
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried both ' and " and it ends up in error.... Or maybe we are not on the same point?


Anyway.. I just paste the value = false on the catalina server config.. Then it now allows it... But i don't know if that is the standard...
 
victor chiong
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know basic html from w3schools... I will review what you mean..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problems like this can be completely avoided by not using obsolete and discredited scriptlets on your JSP pages.

Using the EL, the fragment would be: value="${params.userName}"

There are many good reasons that scriptlets are discredited; this is just one of them.

Please read this JspFaq entry.
 
victor chiong
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Thank you very much. I will try that too I am studying JEE by Head First. Thanks for helping me guys.. I really want to learn this stuff

regards,
Vic
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic