4

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?

5
  • how do you package your WAR? maven? Commented Nov 13, 2012 at 13:37
  • @YevgeniyM. I have an ant script that does the work. Why? Commented Nov 13, 2012 at 13:56
  • i recall similar problems when using filtering without encoding being set in pom.xml Commented Nov 13, 2012 at 14:31
  • @YevgeniyM. I do am using filters. Commented Nov 13, 2012 at 15:21
  • this answer would help, if it was maven: stackoverflow.com/questions/3017695/… Commented Nov 14, 2012 at 7:06

3 Answers 3

4

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">
      <%-- í = &iacute; --%>
      <jsp:param name="title" value="T&iacute;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 know it is not the best solution, but it worked for me.


Edit

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"); %>

Sign up to request clarification or add additional context in comments.

1 Comment

This solution worked for me (From your EDIT). Weird. Honestly, i don't like using this before an include.. its somewhat counter-productive.
1

Could the param value be dinamic? . If not, replace "í" for

&#237;

1 Comment

Well this is hardly ideal, but it no other solution presents itself I can live with this
1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.