0

I want to print some IRIs in a jsp page. When I use System.out.println to print the content into the system the result is fine e.g. http:blabla. However, when I use PrintWriter to print the content into the html page the result is an empty string.

Mohamed Ayadi
  • 83
  • 1
  • 8
Cheryl
  • 245
  • 1
  • 12

1 Answers1

1

If you want to see them in an html page (not as code) you require to print the symbols as "HTML entities". HTML entities start with an AMPERSAND symbol and end with SEMI COLON.

less than is [AMPERSAND]lt[SEMI COLON]

greater than is [AMPERSAND]gt[SEMI COLON]

If it is in a string in a programming language the symbol may need a \ backslash character to delimit it both in the string and for outputting by some print method.

If you printed to an html page right click on it and press "view page source" on the menu.

Samuel Marchant
  • 331
  • 2
  • 6
  • The problem is not that only the <, > are not printed but the whole content inside them – Cheryl Jun 02 '21 at 08:32
  • That is normal: your HTML is not valid, the browser tries its best to display something, but isn't required to. – Piotr P. Karwasz Jun 02 '21 at 08:35
  • what do you means is not valid? I cant edit the above comment but the url is < http:// bla bla> – Cheryl Jun 02 '21 at 08:54
  • 1
    As explained by Samuel, a valid HTML can not contain unescaped `<` characters as text. See [this answer](https://stackoverflow.com/a/25612313/11748454). Your browser probably interprets everything between `<` and `>` as an unknown tag name and ignores it (although `http://...` is not a valid tag name either). – Piotr P. Karwasz Jun 02 '21 at 09:27