• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

decoding double quote in input value

 
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
 
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.
 
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will be a happier man!
 
Legend has it that if you rub the right tiny ad, a genie comes out.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic