• 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

how to avoid HTML elements from being interpreted for some text.

 
Greenhorn
Posts: 6
Eclipse IDE Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am new to JSP and Servlets. However, with my preliminary study i have developed a simple application that reads an input from the user and displays the text on the page. i.e. user inputs some text in a textarea and the same is stored in Database and is shown back to the user. This works fine if the user inputs a simple string i.e. without any HTML element. (for example: Hello, this i my comment.) However if the user enters something like "<b>Hello</b>, this is my comment." This gets stored as it is in the database but while showing it back on page it shows Hello in bold letters. How do i avoid this ?

I am sorry if i have asked this under a wrong category. Please move it to correct category.

with Best Regards,
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to "escape" the html.
Check out http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html
 
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
When you use the EL to display the value, the HTML will automatically be escaped.

So can we assume that for some reason yu are not using the EL?
 
reply
    Bookmark Topic Watch Topic
  • New Topic