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 ?????????
在web.xml中把url-pattern改成/就行了
這是我以前寫的一個hello world小demo。 https://github.com/HelloListe...
另外,建議使用
spring boot
。web-inf 是看不見的,需要內部跳轉,你或把這個jsp提出來,或是自己在jsp上寫一個redirect