Reputation: 14719
So I have several .jsp files:
one of the files has the head tag and has the title of the page:
<%@ page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${param.title}</title>
</head>
The other files include the first one and pass to it a param using jsp:param:
<%@ page pageEncoding="UTF-8"%>
<jsp:include page="consoleheader.jsp">
<jsp:param name="title" value="Título"/>
</jsp:include>
<body>
...
</body>
</html>
Any non-ASCII characters that I pass using jsp:param are getting garbled when I do this (the í in Título for instance). Everywhere else it works fine. All jsp files are encoded using UTF-8. I have not set any charset configurations on my JVM. Anyone knows how to fix this without setting the JVM encoding by hand?
Upvotes: 4
Views: 4826
Reputation: 643
I had a similar problem with jsp params and hacked it in the following way:
main.jsp:
<%@ page pageEncoding="UTF-8"%>
<html>
<head/>
<body>
<jsp:include page="other.jsp">
<%-- í = í --%>
<jsp:param name="title" value="Título"/>
</jsp:include>
</body>
</html>
other.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page pageEncoding="UTF-8"%>
<h1><c:out value="${param.title}" escapeXml="false"/></h1>
I found an other solution that is could work for you too:
Adding the setCharacterEncoding line below before the jsp:include does the trick.
<% request.setCharacterEncoding("utf-8"); %>
Upvotes: 4
Reputation: 14719
Using JSTL worked here. It's more verbose though:
"head":
<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${title}</title>
</head>
"body":
<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="title" scope="request" value="Título"/>
<jsp:include page="consoleheader.jsp">
<body>
...
</body>
</html>
Upvotes: 1
Reputation: 131
Could the param value be dinamic? . If not, replace "í" for
í
Upvotes: 1