There is a bug in Jasper compiler that incorrectly assigns ISO-8859-1 encoding for included file when including files using <%@ include file="..."> directive and the included file contains <%@ page > directive. For example: page1.jsp: <%@ page contentType="text/html; charset=ISO-8859-2" %> Test łćżĆŁŃ <br><br> <%@ include file="page2.jsp"%> page2.jsp: <%@ page import="java.util.*" %> Test łćżĆŁŃ <br><br> Jasper correctly recognizes encoding of file page1.jsp as ISO-8859-2. Since page2.jsp does not have its encoding set and it is included from page1.jsp, it should also have ISO-8859-2 encoding. Jasper incorrectly treats this file as having ISO-8859-1 encoding. The problem disappears when <%@ page import="java.util.*" %> directive is removed from page2.jsp. Patch for this bug follows: Index: ParserController.java =================================================================== RCS file: /home/cvspublic/jakarta-tomcat- jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java,v retrieving revision 1.4.2.1 diff -c -r1.4.2.1 ParserController.java *** ParserController.java 18 Jul 2002 18:04:24 -0000 1.4.2.1 --- ParserController.java 5 Jan 2004 12:52:09 -0000 *************** *** 260,270 **** int loc = contentType.indexOf("charset="); if (loc != -1) { newEncoding = contentType.substring(loc+8); - return; } } - if (newEncoding == null) - newEncoding = "ISO-8859-1"; } else { return; } --- 260,270 ---- int loc = contentType.indexOf("charset="); if (loc != -1) { newEncoding = contentType.substring(loc+8); } + if (newEncoding == null) + newEncoding = "ISO-8859-1"; + return; } } else { return; }
Could we have some update on this bug? I can confirm this for tomcat 4.1.31 as well As a workaround, just put the import page directive into a new file and include this file from the original location. I'll add "pageEncoding" to the summary to make this more visible.
This has been fixed in CVS for 4.1.x. Please note that the suggested patch is bad as it does not take account of JSP 1.2 errata (rev a) of 21 March 2002 which clarifies a number of issues regarding page encoding. An alternative patch has been applied.
*** Bug 29386 has been marked as a duplicate of this bug. ***