Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Wrong characters in portlets with special characters
I have a Liferay 7.1 Tomcat bundle in a Fedora OS. When I load a portlet with special characters (á, é, ñ...) they are showed like this:
The settings that can affect the character encoding, I have them like this:
- Tomcat starts with parameter
-Dfile.encoding=UTF8
- In Eclipse, the JSP file uses
UTF-8
encoding - In the web page source code I can see this tag:
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
. - Watching the System properties in the Portal
Control Panel, the value of the property
file.encoding
isUTF-8
If I put the same text in the Language.properties
file
and I load it with the liferay-ui:message
tag, the text
appears correctly.
If I place the snippet <%@ page
pageEncoding="UTF-8" %>
at the top of the JSP
the text appears correctly too.
I made sure with another text editor (Geany) that JSP encoding is UTF-8.
Other things I tried that haven't worked:
- I added this configuration in build.gradle
file:
compileJava.options.encoding = 'UTF-8' tasks.withType(JavaCompile) { options.encoding = 'UTF-8' }
- I have tried to make a portlet using Maven.
- I have used the portal with Hypersonic DB and MySQL (with CHARACTER SET UTF-8).
Any idea?
Regards.
For URLs, UTF8 chars have to be encoded, they cannot be in the URL as-is.
Whatever is building your URL is not properly encoding the UTF8 chars.
The problem is not related with the URL. I'll give you an example.
I have this code in my view.jsp
file:
<%@ include file="/init.jsp" %> <p>Álava Épico Sísmico Metódico Lúdico España</p>
When I deploy the portlet, it is showed like this in the portal:
Ãlava Ãpico SÃsmico Metódico Lúdico España
Carlos Durán:The problem is not related with the URL. I'll give you an example.
It could be the build process, packaging the files in unexpected encoding. Check the artifact JAR or WAR file: Unpack and analyze the resources in there.
In older versions, Liferay language resources (e.g.
Language.properties) needed to be UTF-8 encoded. I'm not aware if this
is still the case or not - but it's a potential point for confusion.
Regular build tools will encode them in ISO-8859-1
After compile project (using gradlew deploy
), I've
unzipped de JAR generated and I've opened the view.jsp file to make
sure the encoding (and it is UTF-8).
I've deployed the JAR file in the portal and I've founded the file liferay-ce-portal-7.1.1-ga2/work/org.tests.liferay-1.0.0/org/apache/jsp/view_jsp.java with this content:
package org.apache.jsp; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; public final class view_jsp extends org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent { private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory(); private static java.util.List<String> _jspx_dependants; static { _jspx_dependants = new java.util.ArrayList<String>(7); _jspx_dependants.add("/init.jsp"); _jspx_dependants.add("/META-INF/c.tld"); _jspx_dependants.add("/META-INF/liferay-portlet_2_0.tld"); _jspx_dependants.add("/META-INF/liferay-aui.tld"); _jspx_dependants.add("/META-INF/liferay-portlet-ext.tld"); _jspx_dependants.add("/META-INF/liferay-theme.tld"); _jspx_dependants.add("/META-INF/liferay-ui.tld"); } private org.apache.jasper.runtime.TagHandlerPool _jspx_tagPool_liferay$1theme_defineObjects_nobody; private org.apache.jasper.runtime.TagHandlerPool _jspx_tagPool_portlet_defineObjects_nobody; private org.glassfish.jsp.api.ResourceInjector _jspx_resourceInjector; public java.util.List<String> getDependants() { return _jspx_dependants; } public void _jspInit() { _jspx_tagPool_liferay$1theme_defineObjects_nobody = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig()); _jspx_tagPool_portlet_defineObjects_nobody = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig()); } public void _jspDestroy() { _jspx_tagPool_liferay$1theme_defineObjects_nobody.release(); _jspx_tagPool_portlet_defineObjects_nobody.release(); } public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); // liferay-theme:defineObjects com.liferay.taglib.theme.DefineObjectsTag _jspx_th_liferay$1theme_defineObjects_0 = (com.liferay.taglib.theme.DefineObjectsTag) _jspx_tagPool_liferay$1theme_defineObjects_nobody.get(com.liferay.taglib.theme.DefineObjectsTag.class); _jspx_th_liferay$1theme_defineObjects_0.setPageContext(_jspx_page_context); _jspx_th_liferay$1theme_defineObjects_0.setParent(null); int _jspx_eval_liferay$1theme_defineObjects_0 = _jspx_th_liferay$1theme_defineObjects_0.doStartTag(); if (_jspx_th_liferay$1theme_defineObjects_0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { _jspx_tagPool_liferay$1theme_defineObjects_nobody.reuse(_jspx_th_liferay$1theme_defineObjects_0); return; } _jspx_tagPool_liferay$1theme_defineObjects_nobody.reuse(_jspx_th_liferay$1theme_defineObjects_0); out.write('\n'); out.write('\n'); // portlet:defineObjects com.liferay.taglib.portlet.DefineObjectsTag _jspx_th_portlet_defineObjects_0 = (com.liferay.taglib.portlet.DefineObjectsTag) _jspx_tagPool_portlet_defineObjects_nobody.get(com.liferay.taglib.portlet.DefineObjectsTag.class); _jspx_th_portlet_defineObjects_0.setPageContext(_jspx_page_context); _jspx_th_portlet_defineObjects_0.setParent(null); int _jspx_eval_portlet_defineObjects_0 = _jspx_th_portlet_defineObjects_0.doStartTag(); if (_jspx_th_portlet_defineObjects_0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { _jspx_tagPool_portlet_defineObjects_nobody.reuse(_jspx_th_portlet_defineObjects_0); return; } _jspx_tagPool_portlet_defineObjects_nobody.reuse(_jspx_th_portlet_defineObjects_0); out.write("\n"); out.write("\n"); out.write("<p>Ãlava Ãpico SÃsmico Metódico Lúdico España</p>\n"); } catch (Throwable t) { if (!(t instanceof SkipPageException)){ out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } } }
I think the problem is that is generating the line
out.write("<p>Ãlava Ãpico SÃsmico Metódico Lúdico España</p>\n");
but I don't know why it is happening.
Finally, I found a solution.
It seems that I had to compile the project using the ISO-8859-1 encoding in the JSP file. Now the special characters are displayed correctly.
Thanks for the help!