• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Converting &, > " and other odd characters

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would like to hear your recommendation on any good utility or Javascript that would convert &, >, <, ", and other odd-ball characters for display purposes in JSP.

It is for a JSP that displays data as:
<%=myValue%>

The content of myValue needs to be properly displayed.

JSTL, escapeXML etc. is not in use.

Thanks in advance,
SG
 
Sam Gehouse
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, cannot use StringEscapeUtils of Apache as that version of jar is not in the project.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you've just discounted the most common solutions I would suggest.

JSTL <c:out> tag would do that for you. As will the struts <bean:write>
The Jakarta commons StringUtils would have been my next stop.

A quick google search finds this bit of code:
http://www.javapractices.com/Topic96.cjp

Or you could always reinvent the square wheel yourself.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

JSTL, escapeXML etc. is not in use.


Why not?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Also, cannot use StringEscapeUtils of Apache as that version of jar is not in the project.



Copy it into a class of your own naming, pretend you wrote it, ask for a bonus?

Seriously, I was in the same position and copied what I thought I needed from there to my own class. Silly rules about open source.
[ October 27, 2007: Message edited by: Stan James ]
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This topic just came up for me too, and using the JSTL <c:out> tag worked great.

I had been using the JSP EL to set the value for HTML form elements. My question is whether its good practice to always wrapper the EL statement with <c:out>, or is this typically done only when characters such as ", <, &, etc. are expected and thus need to be encoded?

Thanks,
Joe
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the source of the text is untrusted (as is all user input) or unknown, it should be protected via encoding.
 
reply
    Bookmark Topic Watch Topic
  • New Topic