加上 <mvc:default-servlet-handler/> 就不能进入 Controller了
我的配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.sf.web" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
p:messageConverters-ref="messageConverters">
</bean>
<util:list id="messageConverters">
<bean
class="org.springframework.http.converter.BufferedImageHttpMessageConverter" />
<bean
class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
<bean
class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
<bean
class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"
p:marshaller-ref="xmlMarshaller" p:unmarshaller-ref="xmlMarshaller">
</bean>
<bean
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</util:list>
<bean id="xmlMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="streamDriver">
<bean class="com.thoughtworks.xstream.io.xml.StaxDriver" />
</property>
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:order="100" p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/WEB-INF/views/" p:suffix=".jsp" />
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"
p:order="10" />
<!--Excel视图解析器配置
<bean id="userListExcel" class="com.baobaotao.web.UserListExcelView" />
<bean id="userListPdf" class="com.baobaotao.web.UserListPdfView" />
-->
<!-- XMl及JSON视图解析器配置 -->
<bean id="subListJson"
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"
p:renderedAttributes="subList" />
<!-- 静态资源映射
<mvc:default-servlet-handler/>
-->
</beans>
原因 我没有找到 但可以参考 http://m.oschina.net/blog/76484
采用了web中配置方式
<!-- 静态资源 映射-->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.class</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.ico</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.svg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
另:静态资源的配置方式 http://liqipan.iteye.com/blog/1553276
分享到:
相关推荐
- **排除默认拦截器**:如果`<mvc:annotation-driven />`包含默认拦截器,可以考虑使用`<mvc:default-servlet-handler>`或`<mvc:annotation-driven enable-matrix-variables="false" />`来禁用它们。 - **调整拦截器...
- **不处理静态资源**:通过`<mvc:default-servlet-handler/>`让Servlet容器处理静态资源。 - **启用注解驱动**:使用`<mvc:annotation-driven/>`来启用Spring MVC的注解功能。 - **配置视图解析器**:定义视图解析...
spring-servlet.xml 文件名是根据上面 web.xml 中 <servlet-name> 标签的值生成的,例如,如果 <servlet-name> 为 springMVC,那么对应的文件名为 springMVC-servlet.xml。 <?xml version="1.0" encoding="UTF-8"?>...
- **解决方法**:在Spring配置文件中添加`<mvc:default-servlet-handler/>`标签。该标签告诉Spring MVC框架,如果找不到任何匹配的处理器,则将请求转发给Web服务器的默认Servlet。这意味着对于那些未被Spring MVC...
pattern配置的是/),当配置文件中有对静态资源的处理 <mvc:default-servlet-handler/> 时候 ,先匹配 welcome-file-list 中的文件,依次查找,找到了就 返回,如果没有找到就继续匹配到controller 例如附件例子...
<servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern> <url-pattern>*.css</url-pattern> </servlet-mapping> ``` 过滤器与拦截器的区别 过滤器与拦截器都是用于拦截请求的机制,但它们有所...
3. **Spring MVC配置文件**:配置`<mvc:annotation-driven/>`来启用基于注解的配置,以及`<mvc:default-servlet-handler/>`来处理静态资源请求。 ```xml <beans xmlns=...
<mvc:default-servlet-handler /> <aop:config proxy-target-class="true"/> <tx:annotation-driven transaction-manager="txManager"/> <!-- 采用单数据源事务控制方式,通过注解来定义事务--> <bean ...
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-mvc-config.xml</param-...
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-...
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/springmvc-servlet.xml</param-...
<prop key="/**">defaultServletHandler</prop> </props> </property> <property name="order" value="0" /> <!-- 确保此配置优先 --> </bean> <bean id="defaultServletHandler" class="org.springframework....
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>blog</servlet-name> <url-pattern>*....
-- 可以自定义 servlet.xml 配置文件的位置和名称,默认为 WEB-INF 目录下,名称为[<servlet-name>]-servlet.xml,如 spring-servlet.xml --> <init-param> <param-name>contextConfigLocation</param-name> ...
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context...
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/> <!-- 处理器适配器 --> <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/> ``` **5. ...
<title>后台管理</title> <meta name="description" content="overview & stats" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <!-- basic styles --> <link ...