Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cleanly set the pageEncoding of all my JSPs?

I need to encode all of my JSPs as UTF-8.

I've looked around and found that I can use the following page directive to accomplish this:

<%@page pageEncoding="UTF-8"%>

This works perfectly, but I need a way to include that directive to all of my JSPs. I don't want to paste it at the top of each JSP file in my project.

I have a header file that all my JSPs use to display the page header. I'd like to be able to set the page encoding in the included header file, and have it apply to the page that's including it. Unfortunately, from reading this, it looks like the <%@ page %> directive only carries on to the children includes, so I can't just set the encoding in the header because the encoding won't be inherited by the actual page.

Can anyone give me a clean way to set the character encoding on all of my JSPs?

like image 633
ampersandre Avatar asked Jun 13 '11 22:06

ampersandre


1 Answers

Put the following in your web.xml to achieve the goal.

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>

See also:

  • Unicode - How to get the characters right? - JSP/Servlet response
like image 174
BalusC Avatar answered Oct 22 '22 23:10

BalusC