如何干净地设置所有 JSP 的 pageEncoding? [英] How can I cleanly set the pageEncoding of all my JSPs?

查看:27
本文介绍了如何干净地设置所有 JSP 的 pageEncoding?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将所有 JSP 编码为 UTF-8.

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"%>

这很完美,但是我需要一种方法来将该指令包含到我的所有 JSP 中.我不想把它粘贴到我项目中每个 JSP 文件的顶部.

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.

我有一个头文件,我所有的 JSP 都用它来显示页眉.我希望能够在包含的头文件中设置页面编码,并将其应用于包含它的页面.不幸的是,从阅读这个来看,它看起来像<%@ page %> 指令只对子包含进行,所以我不能只在标题中设置编码,因为编码不会被实际页面继承.

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.

谁能给我一个干净的方法来在我所有的 JSP 上设置字符编码?

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

推荐答案

将以下内容放入您的 web.xml 以实现目标.

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>

另见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆