tags:

views:

63

answers:

3

Hello, my fellow developers.

When you write JSP, what's the best way to specify page encoding?

Shoud I use a page directive like this?

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

Or can I directly put it in a meta tag?

<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>

Eclipse by default uses both, so does that mean I need both?

Thanks in advance!

+5  A: 

You don't need both. Actually, <@ page pageEncoding="utf-8" %> suffices.

Bozho
A: 

I would think that you need both, don't you? My guess is that the page directive tells the Container to compile the JSP using the specified encoding and the meta tag tells the browser how the page is encoded.

Michael Angstadt
The page directive implicitly sets the appropriate response header as well.
BalusC
Oh that makes sense.
Michael Angstadt
A: 

In case you need to use UTF-8, you also need to set the charset for your connection url as well as the request and response.

Truong Ha