美文网首页
SpringMVC配置跳转html、jsp

SpringMVC配置跳转html、jsp

作者: Unclezs | 来源:发表于2019-04-06 17:47 被阅读0次

    依赖

        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context-support</artifactId>
          <version>${spring.version}</version>
        </dependency>
        <dependency>
          <groupId>org.freemarker</groupId>
          <artifactId>freemarker-gae</artifactId>
          <version>2.3.27-incubating</version>
    

    配置文件

        <!-- 配置jsp视图解析器 -->
        <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/pages/jsp/"/>
            <property name="suffix" value=".jsp"/>
            <property name="contentType" value="text/html;charset=utf8"/>
        </bean>
        <!-- 配置html视图解析器 -->
        <bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
            <property name="templateLoaderPath">
                <value>/WEB-INF/pages/html/</value>
            </property>
        </bean>
        <bean id="htmlviewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
            <property name="suffix" value=".html" />
            <property name="order" value="0"/>
            <property name="contentType" value="text/html;charset=UTF-8"/>
        </bean>
    

    配置统一跳转错误页面404.html

    异常处理器
    public class MyExecptionResolver implements HandlerExceptionResolver {
        public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
            ModelAndView mv=new ModelAndView();
            mv.setViewName("404");
            return mv;
        }
    }
    
    
    注册异常处理器
        <bean id="myExecptionResolver" class="com.unclezs.resolver.MyExecptionResolver"/>
    

    相关文章

      网友评论

          本文标题:SpringMVC配置跳转html、jsp

          本文链接:https://www.haomeiwen.com/subject/xezriqtx.html