common.jsp
<c:choose>
<c:when test="${param.charset == 'utf-8' }">
<c:set var="charset" value="utf-8" scope="request"/>
</c:when>
<c:otherwise>
<c:set var="charset" value="gbk" scope="request"/>
</c:otherwise>
</c:choose>
xxx.jsp
//charset 要先指定,在根据请求参数修改才行,不然还是会有乱码
<%@ page contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%@ include file="../../common.jsp"%><%
if (request.getAttribute("charset").equals("utf-8")) {
response.setContentType("text/html; charset=UTF-8");
} else {
response.setContentType("text/html; charset=gbk");
}