aspose file tools*
The moose likes JSP and the fly likes Converting &, > Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Converting &, > " and other odd characters" Watch "Converting &, > " and other odd characters" New topic
Author

Converting &, > " and other odd characters

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
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

Joined: Jul 21, 2003
Posts: 281
Also, cannot use StringEscapeUtils of Apache as that version of jar is not in the project.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1026
Well you've just discounted the most common solutions I would suggest.

JSTL <cut> 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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61753
    
  67

JSTL, escapeXML etc. is not in use.

Why not?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joe Gliniecki
Greenhorn

Joined: Oct 25, 2007
Posts: 18
This topic just came up for me too, and using the JSTL <cut> 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 <cut>, or is this typically done only when characters such as ", <, &, etc. are expected and thus need to be encoded?

Thanks,
Joe
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61753
    
  67

If the source of the text is untrusted (as is all user input) or unknown, it should be protected via encoding.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting &, > " and other odd characters