JSF Url解码希腊字符

时间:2016-01-05 18:19:02

标签: jsf decoding

我有一些jsf文件的问题没有将正确的希腊字符作为

传递给它的控制器
<f:viewParam>

目前我正在对α(alpha)字符进行编码并将其传递到编码为https://rooturl?tag=%CE%B1+testing

的网址中。

然而当我实施

<f:viewParam name="tag" value="#{controller.itemName}" />

设置bean值,而不是将其设置为α测试值。

Sofar香港专业教育学院尝试按照其他网站的建议实施“CharacterEncodingFilter”:

public class CharacterEncodingFilter implements Filter {

/** The default character encoding to set for request / response. */
private String encoding = null;

/** The filter configuration object. */
private FilterConfig filterConfig;

/** Should a character encoding specified by the client be ignored? */
private boolean ignore = true;

public void destroy() {
    encoding = null;
    filterConfig = null;
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
        ServletException {
    // conditionally select and set the character encoding to be used
    if ((ignore || (request.getCharacterEncoding() == null)) && (encoding != null)) {
        request.setCharacterEncoding(encoding);
        response.setCharacterEncoding(encoding);
    }

    // pass control on to the next filter
    chain.doFilter(request, response);
}

public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    this.encoding = filterConfig.getInitParameter("encoding");

    String value = filterConfig.getInitParameter("ignore");

    this.ignore = ((value == null) || value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"));
}
}

并将过滤器添加到web.xml文件

<filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>mypackage.CharacterEncodingFilter</filter-class>
    <init-param>
        <description>override any encodings from client</description>
        <param-name>ignore</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <description>the encoding to use</description>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/myurl/*</url-pattern>
</filter-mapping>

我还修改了xhtml文件以包含

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

标记符合其他网站的建议。然而,这些修改似乎都没有改变行为,我仍然得到不正确的角色。

有关如何让JSF获取正确值的任何帮助都将非常感激。

0 个答案:

没有答案