spring mvc 一个的配置问题

J2EE 码拜 8年前 (2016-05-31) 1375次浏览
碰到一个spring mvc 的配置问题,由于本人 对spring mvc 的配置理解的不是很通透 还望高手解释下,废话不说
1、这是本人在web.xml 文件中配置假如这样配置:
spring mvc 一个的配置问题
那么通过controller 跳转到jsp 返回的就是 jsp 没有编译成servlet 执行很奇怪
spring mvc 一个的配置问题
2、假如本人改成
spring mvc 一个的配置问题
就正常了,
spring mvc 一个的配置问题
问一下这是为什么呢?
另外贴上本人的web.xml文件和servlet-mvc.xml文件
web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
	<display-name>jack</display-name>
	 <!-- ********************************** Spring ********************************** -->
 
	 
	<!--********************************** encodingFilter **********************************-->
	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

 
	<!--********************************** servlet **********************************-->
	<servlet>
		<servlet-name>spring</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>spring</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
<!-- 
	<servlet>
		<servlet-name>initServlet</servlet-name>
		<servlet-class>com.jumbo.pepsitmall.web.servlet.InitServlet</servlet-class>
		<load-on-startup>2</load-on-startup>
	</servlet>
 -->
	<jsp-config>
		<jsp-property-group>
			<description>Special property group for JSP Configuration JSP example.</description>
			<display-name>JSPConfiguration</display-name>
			<url-pattern>*.jsp</url-pattern>
			<page-encoding>UTF-8</page-encoding>
		</jsp-property-group>
	</jsp-config>
 
	<error-page>
		<exception-type>400</exception-type>
		<location>/error/404.jsp</location>
	</error-page>
	<error-page>
		<error-code>404</error-code>
		<location>/error/404.jsp</location>
	</error-page>
	<error-page>
		<error-code>500</error-code>
		<location>/error/500.jsp</location>
	</error-page>
	<error-page>
		<exception-type>java.lang.Exception</exception-type>
		<location>/error/sorry.jsp</location>
	</error-page>
	<session-config>
		<session-timeout>30</session-timeout>
	</session-config>

	 

</web-app>

servlet-mvc.xml

<?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"
       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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
 
 	<context:component-scan base-package="com.jack.myproject.web"/> 
 
    <mvc:annotation-driven/>
    <mvc:resources mapping="/images/**" location="/images/"/>
    <mvc:resources mapping="/css/**" location="/css/"/>
    <mvc:resources mapping="/scripts/**" location="/scripts/"/> 
    
   <mvc:default-servlet-handler/>
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:viewClass="org.springframework.web.servlet.view.JstlView"
          p:order="1"
          p:contentType="text/html;charset=utf-8"
          p:prefix="/WEB-INF/views/"
          p:suffix=".jsp"
          p:cache="true"
            />  
    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
          p:defaultEncoding="utf-8"
          p:maxInMemorySize="100000000"
            />
</beans>
解决方案

20

<url-pattern>/</url-pattern>
一、
/采用的是时下用的很多的REST风格,它会拦截.js,.jpg(等).css静态文件,而使用/*则会拦截全部请求,包括.js,.jpg(等).css静态文件以及.jsp。
重点就是这个.jsp,/ 不会拦截.jsp,全部就可以解析出来,而 /* 拦截下来的 .jsp  ,可能是springmvc造成了jsp请求”变异“,成为了文本,直接以文本方式输出了。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明spring mvc 一个的配置问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)