java - spring mvc页面跳转报404
大家讲道理
大家讲道理 2017-04-18 09:41:32
0
3
611
spring-mvc拦截器

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!--// 不是用默认过滤规则(指定包内全部扫描), 手动设置规则,只扫描@Controller注解的类。-->
    <context:component-scan base-package="com.prs.dps" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!--启用 MVC注解(@Controller,@RequestMapping)实现URL映射-->
    <mvc:annotation-driven/>



    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 -->
    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 默认编码 -->
        <property name="defaultEncoding" value="utf-8" />
        <!-- 文件大小最大值 -->
        <property name="maxUploadSize" value="10485760000" />
        <!-- 内存中的最大值 -->
        <property name="maxInMemorySize" value="40960" />
    </bean>
</beans>

程序启动后日志:
23-Jul-2016 14:05:35.050 WARNING [http-apr-8080-exec-2] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/dps/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dps'
23-Jul-2016 14:05:37.841 WARNING [http-apr-8080-exec-7] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/dps/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dps'

web根目录变成了/dps/WEB-INF而不是/WEB-INF ?????????

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

모든 응답(3)
小葫芦

web.xml에서 url-pattern을 /로 변경하세요

으아악
洪涛

이것은 제가 이전에 작성한 작은 Hello World 데모입니다. https://github.com/HelloListe...

또한 spring boot을 사용하는 것이 좋습니다.

黄舟

web-inf는 보이지 않으며 내부 점프가 필요합니다. 이 jsp를 추출하거나 jsp에 직접 리디렉션을 작성할 수 있습니다.

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿