jsp关于include html、jsp等文件出现乱码问题的解决方案

一般来说使用jsp标签<jsp:include>引入一个jsp文件:

①可以在被引入的jsp中加入:<%@ page contentType="text/html;charset=UTF-8" language="java" %>

②在当前项目的web.xml中加入:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 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"> <jsp-config>
<jsp-property-group>
<description>jsp encoding example</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.jsp</url-pattern>
<el-ignored>false</el-ignored>
<page-encoding>UTF-8</page-encoding>
<scripting-invalid>false</scripting-invalid>
</jsp-property-group> <jsp-property-group>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.html</url-pattern>
<el-ignored>false</el-ignored>
<page-encoding>UTF-8</page-encoding>
<scripting-invalid>false</scripting-invalid>
</jsp-property-group> <jsp-property-group>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.ftl</url-pattern>
<el-ignored>false</el-ignored>
<page-encoding>UTF-8</page-encoding>
<scripting-invalid>false</scripting-invalid>
</jsp-property-group>
</jsp-config> </web-app>

提示:在有些编译器中可能会提示错误,但是加入后仍可以运行,并且没有出现什么致命错误。

上一篇:多线程基础(五)NSThread线程通信


下一篇:C#编程总结(二)多线程基础