0

Using JSP on a Tomcat I need to load a CSV file and then create an XML output for it to show be shown in the screen. My problem is that sometime this CSV file has special characters like ç, á, é, ó, etc. And in the Web Output (screen) I need to print the ISO-8859-1 entities equivalency, say, instead of ç I need to show ç

So word açucar needs to be shown as: açucar

I can read the CSV file but can't figure out how to tell JSP to print those html entities as I need to.

So if CSV file is:

product;quantity;value

açucar;5723;7.00;

I need to print in my screen something like:

<item>
<product>a&amp;#xe7;ucar</product>
<quantity>5723</quantity>
<value>7.00</value>
</item>

Any idea how to do this?

1 Answers1

0

Why can't you just use UTF-8 or something like that? Surely any web browser should accept it.

Otherwise, you might want to have a look at this: Recommended method for escaping HTML in Java

Community
  • 1
  • 1
Thijs Steel
  • 1,190
  • 7
  • 16
  • Hi, you mean the UTF-8 in the CSV file? Because is a direct output from an external DB and I have no control on that – Jorge Cornejo Bellido May 04 '17 at 16:49
  • No, i mean in the output. Although you should be aware of the charset of the CSV file too. I'll assume you just weird characters right now. This might be because you actually read the csv wrong. – Thijs Steel May 04 '17 at 17:02
  • You could convert the input you get to UTF-8 and then add this to jsp page directive <%@page contentType="text/html;charset=UTF-8"%>. – Thijs Steel May 04 '17 at 17:12
  • No weird characters, only international ones. Encoding isn't the solution. That is working fine. The escapeHtml is a part of the solution. Will test it further and let you know. – Jorge Cornejo Bellido May 04 '17 at 18:18