• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass strings with double quotes to method out.println()

 
Gerard Largosa
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the method out.println("") to output Javascript/html strings from my JSP file. The string I am passing to this method contains double quotes which cannot be substituted with a single quote. Ofcourse it does not work, since there is are double quotes inside the string I am passing. Is there some sort of way around this issue? Like some substitute character which translates back to a double quote. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gerard Largosa:
I am using the method out.println("") to output Javascript/html strings from my JSP file.


Why? I see this anti-pattern a lot. You are already in a template (the JSP) why not use template text?

If that's not possible...

The string I am passing to this method contains double quotes which cannot be substituted with a single quote.


So? This is Java, and Java has means for escaping quotes within strings. What is it about your code that can;t use the normal Java mechanisms for quotes?
 
Gerard Largosa
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it used \" for all double quotes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!