File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Displaying data Containing HTML TAGS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying data Containing HTML TAGS" Watch "Displaying data Containing HTML TAGS" New topic

Displaying data Containing HTML TAGS

Vasilis Karas

Joined: Mar 16, 2004
Posts: 24
We have a DB application that allows users to freely enter data. Our problem is that if a users enters HTML tags as their data and submits it to our DB, we are able to encode the response and store the data in it's original context (a requirement).

Now, here is the problem. When the data is pulled out from the DB and displayed on the .JSP, if the user had submitted HTML tags, our page doesn't display the HTML tags but rather their browser interprets the tag.

We do not want the browser to interpret the tag, just want the actual characters displayed.
so if a user enteres <B> HELLO WORLD</B>
we want the less than and greater than signs to be displayed..not the phrase HELLO WORLD to be displayed in bold.

Any help is appreicated
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
I think the solution is to encode the HTML text before sending it to the browser, e.g. use &lt; and &gt; instead of < and >. You'll need to encode other stuff too such as & with &amp;. I don't know if there's a standard Java API to do this but there must surely be free, open source APIs available.

I agree. Here's the link:
subject: Displaying data Containing HTML TAGS
It's not a secret anymore!