Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

decoding double quote in input value

 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure of the forum this should be in, but thought I'd be safe to start in this one.

I have a JSP that displays string values in HTML input elements. In the code, we enclose the value in double quotes so that string values containing spaces are properly displayed. This was all fine n dandy until someone tried a string containing double quotes. The value displayed would then cut off at the first double quote, since it would see that as the closing quote.

The JSP code in question.



So, I would like to find a way to properly display a string that could potentially contain spaces, double quotes and anything, really. I tried using URLEncoder on the values in the JSP code, and then using javascript to decode, but it basically just ends up at square one. I can't quite wrap my head around what I need to do here, and I've done plenty of googling. There seem to be some PHP methods that take care of this (not positive they do what I need) and I've tried the javascript versions of these, but no luck.

If anyone has any ideas/information on this, I'd appreciate it.

thanks,
Tom
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use JSTL's c:out tag. It by default escapes HTML entities. This has nothing to do with URL encoding or so.

Do not use scriptlets, it's a very bad practice. In JSP you should use taglibs (like JSTL) and EL only.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65542
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Bauke said. But even if you do use scriptlets, what's with the out,prints to emit HTML? That's completely inside-out. The whole purpose of using a JSP is to be able to place the HTML in template text rather than build it up in Java.
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THanks! We don't use JSTL enough in the app, and fixing this problem should give me leeway to make the change.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65542
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will be a happier man!
 
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!