• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP expressions, double quote character, INPUT field

 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question about JSP expressions and the
double quote character.
Example: Plain HTML:

<input type="text"
name="foobar"
value="Hello">

Example: JSP page that contains a JSP expression
<input type="text"
name="foobar"
value="<%= mybean.getFooBarValue() %>">
If getFooBarValue returns a String that contains a double quote character, the page will not render correctly.
Is there an elegant solution?
Are there any "best practices" for dealing with this?
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean
If your returning a double quote character to the browser try to use the escape for it: & quot;
I had to put a space between the & and the rest of it so it doesn't get turned into a ". When you use just make sure there are no spaces in it.
That should do it for you.
[ September 11, 2002: Message edited by: Dave Vick ]
[ September 11, 2002: Message edited by: Dave Vick ]
 
Zac Roberts
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Vick is right, you will definitely need to use escape sequences for this... here is a link to some....
Scroll about half way down on this page...
http://mindprod.com/jcheat.html
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note also that JSTL's standard <cut> tag automatically escape such characters by default. In most situations, it's better to use <cut> than a scriptlet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!