I am currently experimenting with different HTML-encoders to encode user supplied values in my Java web application. I wrote a small sample application that prints the results from the different encoders to a website. This works so far without any issues.
Unfortunately the browser (FireFox) also behaves as expected, displaying the encoded characters in the correct way (e.g. transforms >
into <
). In this special case I do not want this to happen, I want to see the encoded string as it is. I want the browser to display the strings the same way the web server sends them.
The <pre>
tag doesn't work, no success with <code>
either. Is there a HTML-tag I have overlooked to accomplish that? Or is there another trick I can user? I do not want to manipulate the string in any way on the server side with additional encodings, to avoid misleading results.
To make a long question short - how do I get my browser to di开发者_高级运维splay the string 4 > 5
as is and not correctly decoded as 4 < 5
?
If you don't want the browser to treat the document as HTML, then don't serve it as HTML.
In PHP you would do:
<?php
header('Content-Type: text/plain');
print $string;
?>
I don't know the Java syntax.
The
<pre>
tag doesn't work, no success with<code>
either
<pre>
just means white space is significant. <code>
just means "This is an HTML representation of some code".
In this case, you'll actually need to represent the > as HTML entities. So, &gt;
should work I believe.
精彩评论