您的位置:首页 > Web前端 > JavaScript

jsp中的include静态页面出现乱码问题

2010-05-12 17:00 477 查看
在当前应用系统的web.xml里加入jsp-config代码:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<jsp-config>
<jsp-property-group>
<description>
Special property group for JSP Configuration JSP example.
</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GB2312</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>

<description>
Special property group for JSP Configuration JSP example.
</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.html</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GB2312</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>
</jsp-property-group>
</jsp-config>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

... ...

</webapp>


说明:<jsp-config>里的定义,就是通知当前应用服务器,当前应用系统下,所有的 .jsp, .html 文件,若是没有定义contentType="text/html;charset=gb2312" 时,就会采用预设的 "GB2312" 字符集去处理,如此,就不须要在每个 include 的档案第一行加上 contentType="text/html;charset=gb2312" 了。

注:

<jsp-config>标签使用详解

<jsp-config> 包括<taglib> 和<jsp-property-group> 两个子元素。

其中<taglib>元素在JSP 1.2时就已经存在;而<jsp-property-group>是JSP 2.0 新增的元素。
<jsp-property-group>元素主要有八个子元素,它们分别为:

1.<description>:设定的说明;
2.<display-name>:设定名称;
3.<url-pattern>:设定值所影响的范围,如:/CH2 或 /*.jsp;
4.<el-ignored>:若为true,表示不支持EL 语法;
5.<scripting-invalid>:若为true,表示不支持<% scripting %>语法;
6.<page-encoding>:设定JSP 网页的编码;
7.<include-prelude>:设置JSP 网页的抬头,扩展名为.jspf;
8.<include-coda>:设置JSP 网页的结尾,扩展名为.jspf。

tomcat 5中include页面乱码问题
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

<jsp-config>
<jsp-property-group>
<description>Special property group for JSP Configuration JSP example.</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GBK</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>

<description>Special property group for JSP Configuration JSP example.</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.html</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GBK</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>
</jsp-property-group>
</jsp-config>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: