Search code examples
jsppage-directives

JSP Page Directive


I have 2 difference page directive codes in my jsp, i don't know what is the difference between contentType, charset, and pageEncoding, i read thru Oracle JSP Globalization Support but didn't understand quite well , can anyone explain the difference in simpler way?

<%@ page contentType="text/html;charset=GBK"%>

VERSUS

<%@page contentType="text/html;charset=GBK" pageEncoding="GBK"%>

Solution

  • http://www.satollo.net/jsp-and-the-content-type-charset-and-the-page-encoding-attribute

    ContentType charset

    The contentType charset is how the servlet container which runs the JSP must send to the browser the text generated by the page.

    PageEncoding

    The pageEncoding directive is used to correctly read the JSP from the file system. Since even the JSP is a text but a file is a sequence of bytes on disk, it can be correctly read only knowing the charset to use.

    Then:

    ContentType charset: How the client have to interpret the file

    PageEncoding: How to read the jsp from the filesystem