JSP

时间:2016-08-14 13:09:34

标签: jsp spring-mvc unicode

我有一个带有一些JSP文件的SpringMVC应用程序。我一直在尝试将越南字符添加到JSP文件中,但所有字符总是变成乱码。我尝试过的事情:

添加此标记

<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

这一个

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

编写自定义编码过滤器

public class EncodingFilter implements Filter {

    private String encoding = "UTF-8";

    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain)
            throws IOException, ServletException {
        servletRequest.setCharacterEncoding(encoding);
        servletResponse.setCharacterEncoding(encoding);
        filterChain.doFilter(servletRequest, servletResponse);
    }

    public void init(FilterConfig filterConfig) throws ServletException {
        String encodingParam = filterConfig.getInitParameter("encoding");
        if (encodingParam != null) {
            encoding = encodingParam;
        }
    }

    public void destroy() {

    }
}

使用CharacterEncodingFilter:

@Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        return new Filter[] { characterEncodingFilter, new EncodingFilter() };
    }

到目前为止,这些都没有,我确实拥有正确的字体。我已尝试直接在浏览器上进行编辑,并且字符显示正确。我还将我的IDE设置为UTF-8编码。

0 个答案:

没有答案