Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data in textarea is being interpreted as HTML by browser

 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a JSP that's displaying any/all kinds of file data in a text area. Well, I just ran up against the occurrence where this file might be in xml-format, and it gets interpreted as HTML. What results is the </textarea> tag and everything below it is commented out.

Anyone seen this or know of a way to prevent a textarea from allowing this?

thanks
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
escape your server side code returned from the database. change all of the < to ↦lt; and > to &gt;

Eric
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks...

I was just trying that with string.replaceAll("<", ">"), etc. Didnt seem to work, better check and make sure I'm doing it right ))
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops that came out looking wrong because the < was interpreted as html. When I run the replaceAll on the string, it looks the same. Turns out though, removing a valid html comment below the textarea may have fixed this problem. Still got me worried tho...

thanks again
 
Ayan Kumar Roy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can u please post the code?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic