hard coder
hard coder

Reputation: 5715

Special character not correctly visible on Windows deployment

I have J2EE web application that is deployed on tomcat on windows and ubuntu.

There is a text "Raphaël", that I am reading from local file(csv) system, that is coming correctly on ubuntu browsers, but it is coming as "Raphaël" on windows browsers.

I am using in Jsp

<meta charset="utf-8"> 

Also I have tried following meta tags also, but they didn't work.

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

What could be the problem here?

CSV reading code is

reader = new CSVReader(new FileReader(file));
final List<String[]> licenses =  reader.readAll();

Upvotes: 1

Views: 56

Answers (3)

Anton Krosnev
Anton Krosnev

Reputation: 4132

First you need to read the file using correct encoding. The way you read the file depends on the default encoding of J2EE server's JVM, which can be anything. My suggestion is to do something like this:

final FileInputStream instream = new FileInputStream(file);
CSVReader reader = new CSVReader(new InputStreamReader(input, "UTF-8"));

and also set UTF-8 encoding in the JSP as Joseph has written above:

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

Upvotes: 0

user987339
user987339

Reputation: 10707

Check that you have UTF-8 encoding in both CSV file and JVM.

For JVM setting use :

-Dfile.encoding=UTF8

To check file encoding on linux use:

file --mime-encoding file.name

For setting encoding on JSP page use:

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

If that does not help add a filter in order to have proper encoding for all responses:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws ServletException
{
   request.setCharacterEncoding("UTF-8");
   chain.doFilter(request, response);
}

Upvotes: 2

An Do
An Do

Reputation: 309

Set your JSP contentType as UTF-8

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

Upvotes: 0

Related Questions