【发布时间】:2013-06-05 04:42:39
【问题描述】:
我已将 xhtml 设置为 UTF-8 和 ServletRequest。但它似乎仍然无法将字符编码检测为 UTF-8。我正在使用带有 WebSphere 8 的 Primefaces 3.5。
.xhtml
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
重定向登录
public class RedirectLogin implements Filter {
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
chain.doFilter(request, response);
}
}
web.xml
<filter>
<description>Redirect unauthenticated session to login page.</description>
<display-name>RedirectLogin</display-name>
<filter-name>RedirectLogin</filter-name>
<filter-class>com.belsize.servlet.filter.RedirectLogin</filter-class>
<init-param>
<param-name>login_page</param-name>
<param-value>/faces/login.xhtml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>RedirectLogin</filter-name>
<url-pattern>/RedirectLogin</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>RedirectLogin</filter-name>
<url-pattern>*.xhtml</url-pattern>
</filter-mapping>
【问题讨论】:
-
您尝试将
<?xml version="1.0" encoding="UTF-8"?>添加到.xhtml 标头。 -
@RongNK 我在 .xhtml 文件的标题中也有。但不工作。
-
你的意思是:你不能在你的 xhtml 文件中使用 utf-8 格式或者最终用户不能提交 utf-8 格式?
-
@RongNK 我可以输入汉字,但是当我点击一个按钮时,页面会刷新。页面刷新后,汉字变成了一些垃圾文字。
-
你应该是真正的问题,越南语工作正常。
标签: primefaces character-encoding websphere-8