go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  JSP page encoding -- The character encoding of the JSP itself.
 
Subject: JSP page encoding -- The character encoding of the JSP itself.
Author: WebSpider
In response to: Request/response character encoding
Posted on: 11/04/2009 02:19:23 AM

JSP is dynamically compiled at runtime and becomes Java byte code. Java byte code stores strings in Unicode (UTF-8), and, therefore, conversion from JSP page encoding to Unicode is necessary at the time of compilation.

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


There may be cases where JSPs are written in one encoding (GB2312) but the output response in another encoding (UTF-8). In such cases, pageEncoding page directive can be used. One can still specify just the contentType if the charset is the same for both pageEncoding and contentType.

Also note that if the contentType attribute is missing, the value of the pageEncoding is used if provided.

To make the parameter configurable, the dynamic way to do this is as the follows:
      response.setContentType("text/html; charset=UTF-8");


It should be noticed that this settings can override tht static one.

Just a note, the following seems to do the same job.
      response.setCharacterEncoding("UTF-8");



 

> On 11/04/2009 02:11:46 AM WebSpider wrote:

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

JSP is dynamically generated at runtime and transfered to client via a stream. The parameter defined in contentType is used to determine the response charset for this stream encoding.

This parameter is also the one used in the client's broswer for charset encoding.





References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.