• 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

equivalent to <c:out escapeXML="true"> for servlets?

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

Short version of my question: Is there a convenience method somewhere in the Servlet API that will accomplish the same thing the <c:out escapeXML="true"> does?

Long version: I have some html to output from my servlet that should be output "as is", meaning, for example, the browser should see "<textarea>blahblahblah</textarea>" instead a text area in their browser. Before I embark on looping through my output strings and replacing all my '<' characters with "<", I thought I would ask if there is already a function that does that.

Thanks!
John
 
Sheriff
Posts: 67748
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
There is not.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like the org.apache.taglibs.standard.tag.common.core.OutSupport class in the standard tag library provides this static method:

private static void writeEscapedXml(char buffer[], int length, JspWriter w) throws IOException

Perhaps you could make use of that to do the XML escaping for you.

Ditto for org.apache.jasper.tagplugins.jstl.Util:

public static java.lang.String escapeXml(java.lang.String buffer)


Beats having to write the code yourself...
 
Bear Bibeault
Sheriff
Posts: 67748
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
Or, use the same method mapped to ${fn:escapeXml()}:

org.apache.taglibs.standard.functions.escapeXml()

which is in the JSTL's standard jar (which you probably already have loaded into your web app).
 
JohnWilliam Fitz
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both for the replies. I will look at these different possibilities.

But now I have a new question: Where does one find the docs for these packages/classes/methods from Apache?

I searched around for documentation but I can find nothing. I even directly entered "org.apache.taglibs.standard.Functions" into the search field on "apache.org" and none of the hits were documentation. (Well, ok, I did find what appears to be the source code for the Functions class, and I guess source code is really the ultimate documentation, but I was looking for something a little more concise, maybe in javadoc format.)

Thanks for your help!
 
Bear Bibeault
Sheriff
Posts: 67748
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
I opened the JSTL jar files and looked. I knew that there had to be an implementation of ${fn:escapeXml()} so I just looked for it.

Of course, using these methods ties you to the Apache implementation of the JSTL if that matters to you.

By the way, writing your own is a simple 2 or 3 line method if you want to avoid the use of any proprietary methods.
 
JohnWilliam Fitz
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you're right. I wrote my own in the meantime, converting all the "less thans" and "ampersands". I'm just worried I missed some poisonous combination of characters that I should also be watching out for that these other might already know about and handle.

Thanks again.
 
Bear Bibeault
Sheriff
Posts: 67748
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
escapeXML() converts <, > &, single quote and double quote.
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic