Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 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 Answer

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...