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

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

问题描述

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



我已经环顾四周,发现我可以使用下面的page指令来完成这个:

 <%@ page pageEncoding =UTF-8%> 

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



我有一个头文件,所有我的JSP用来显示页眉。我想能够在包含的头文件中设置页面编码,并将其应用于包含它的页面。很遗憾,从阅读开始,它看起来像是 <%@ page%> 指令只对子元素进行,因此我不能只设置标头中的编码,因为编码不会被实际页面继承。 / p>

任何人都可以给我一个干净的方式来设置我的所有JSP的字符编码?

解决方案

在您的 web.xml 中添加以下内容以实现目标。

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



另请参阅:




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?

解决方案

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:

这篇关于如何干净地设置我的所有JSP的pageEncoding?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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