JSP include 乱码解决方案

Categories: Java; Tagged with: ; @ March 25th, 2011 23:25

JSP在include时如果不在被Include文件中声明编码, 在外部文件中将出现乱码. 解决方案就是:

在被Include jsp文件中声明:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

此时如果外部jsp编码为 utf-8 — 即: 两者utf-8大小写不同, 将会出现如下错误:

Page directive: illegal to have multiple occurrences of contentType with different values (old: text/html; charset=utf-8, new: text/html; charset=UTF-8)]

可通过配置Eclipse/MyEclipse jsp文件默认编码来避免不必要的操作: http://liguoliang.com/2011/set-eclipse-jsp-files-encoding-utf-8/


// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.