Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

character encoding - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...