zoukankan      html  css  js  c++  java
  • SpringMVC跳转到html页面以及Controller返回html页面的乱码问题

    一、SpringMVC跳转到html页面
      1、自定义视图解析器:
         public class CustomResourceView extends InternalResourceView {
            @Override
            public boolean checkResource(Locale locale) throws Exception {
                 File file=new File(this.getServletContext().getRealPath("/")+getUrl());
                  return file.exists(); //判断页面是否存在
            }
         }
        2、在dispatcherServlet-config.xml文件中配置视图解析器:
                  <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
              <property name="viewClass" value="ssm.tools.CustomResourceView"/>
              <property name="prefix" value="/WEB-INF/jsp/"/>
              <property name="suffix" value=".jsp"/>
              <property name="order" value="1"/>
            </bean>
            <bean id="htmlViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
               <property name="viewClass" value="ssm.tools.CustomResourceView"/>
               <property name="prefix" value="/WEB-INF/html/"/>
               <property name="suffix" value=".html"/>
                         <property name="order" value="2"/>
            </bean>
     
    二、Controller返回html页面的乱码问题:在web.xml文件中配置字符编码过滤器
                <filter>
            <filter-name>characterEncodingFilter</filter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            <init-param>
               <param-name>encoding</param-name>
               <param-value>UTF8</param-value>
            </init-param>
            <init-param>
               <param-name>forceEncoding</param-name>
               <param-value>false</param-value>
             </init-param>
           </filter>
           <filter-mapping>
              <filter-name>characterEncodingFilter</filter-name>
              <url-pattern>*.html</url-pattern>
           </filter-mapping>
           <filter-mapping>
              <filter-name>characterEncodingFilter</filter-name>
              <url-pattern>*.jsp</url-pattern>
           </filter-mapping>
  • 相关阅读:
    利用js在Table中追加数据
    C#API配置跨域
    C#linq查询DataTable
    erlang格式化输出
    erlang 的源代码保护机制
    MP3格式音频文件结构解析
    使用异步 I/O 大大提高应用程序的性能
    虚拟机安装mac 关键是换引导
    C/C++规则整理
    字节对齐
  • 原文地址:https://www.cnblogs.com/lone5wolf/p/11534002.html
Copyright © 2011-2022 走看看