我尝试将 UTF-8 字符串作为f:viewParam
值传递,但值显示为垃圾字符串,我添加了 EncodingFilter 以web.xml
将 UTF-8 设置为请求和响应,如下所示
HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpServletRequest request = (HttpServletRequest) servletRequest;
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
我用这种风格定义了facelet页面,但问题没有解决
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:metadata>
<f:viewParam name="q" value="#{searchBean.query}"/>
</f:metadata>
.....
</html>
我用 Myfaces 2.0.5 和 Mojarra 2.0.5 对此进行了测试