Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page Encoding in JSP

Tags:

What's the best way to specify page encoding - using a page directive like this?

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

Or should 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?

like image 486
Tom Tucker Avatar asked Aug 29 '10 19:08

Tom Tucker


People also ask

What is contentType in JSP?

The contentType attribute sets the character encoding for the JSP page and for the generated response page. The default content type is text/html, which is the standard content type for HTML pages.


2 Answers

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

like image 129
Bozho Avatar answered Sep 22 '22 05:09

Bozho


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.

like image 29
Michael Avatar answered Sep 21 '22 05:09

Michael