How to use UTF-8 encoding in a JSP custom tag

I have created a custom JSP tag file that looks something like this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ attribute name="title" required="false" rtexprvalue="true" %>

Say hello using some foreign characters in UTF-8 encoding


However, the UTF-8 characters are not displayed properly. I'm sure there is some pretty easy way to configure it, but I couldn't find the proper solution anywhere.
graham on 23-01-2013 20:55
I found it, I just needed to put the following tag at the top of your page:
<%@ tag pageEncoding="UTF-8" %>

So, the full code would be:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ attribute name="title" required="false" rtexprvalue="true" %>
<%@ tag pageEncoding="UTF-8" %>

Say hello using some foreign characters in UTF-8 encoding
graham on 23-01-2013 20:56

Post an answer

Do you have a solution to this problem, or want to comment on it? Other users will appreciate your help!
Your answer or comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems