我有一个工作的MVC应用程序与瓷砖。但是,我遇到了MVC资源问题。如果我没有在我的xml文件中包含mvc:resources或者在html中将它引用到CSS文件中,我可以成功查看这些页面。但是,如果我添加了资源标记,它会给我一个“请求的资源不可用”错误 - 阻止我看到该页面。
你能帮助我确定原因吗?我试图遵循文档和无数的教程 - 但它似乎不起作用。谢谢!
编辑:我知道有很多问题要解决这个问题 - 我浏览过绝大多数问题(Stack Overflow内外)并尝试了解决方案但没有成功。
编辑:经过一些故障排除后,我确定我的控制器已成功访问(通过查看日志记录数据)。它找不到“/ContactManagement/WEB-INF/jsp/layout.jsp”。这仅在我提到时发生。我在视图中注释掉了CSS文件引用;但是,这并不能解决问题。
现在为所有控制器完成映射,以及mvc:resources映射。它只是在访问时遇到问题的.jsp文件。
在我的配置文件中,我通过
包含MVC资源<mvc:resources mapping="/resources/**" location="/resources/" />
我在html中引用为
<link href="<c:url value='/resources/css/default.css'/>" rel="stylesheet" />
我的文件结构是
-WebContent
---resources
------css
------js
------images
---WEB-INF
------jsp
------spring-servlet.xml
------tiles.xml
这是我的spring-servlet.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}"
p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan base-package="mil.navy.navsupbsc" />
这是HTML布局页面的头部
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="type" />
<meta http-equiv="X-UA-Compatible" content="IE=9">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%-- href="<c:url value="/resources/css/default.css"/>" --%>
<link
href="<c:url value='/resources/css/default.css'/>" rel="stylesheet" />
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
以下是我的启动日志
Jan 31, 2014 9:16:26 PM com.springsource.tcserver.security.PropertyDecoder <init>
INFO: tc Runtime property decoder using memory-based key
Jan 31, 2014 9:16:26 PM com.springsource.tcserver.security.PropertyDecoder <init>
INFO: tcServer Runtime property decoder has been initialized in 392 ms
Jan 31, 2014 9:16:27 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-48080"]
Jan 31, 2014 9:16:27 PM com.springsource.tcserver.serviceability.rmi.JmxSocketListener init
INFO: Started up JMX registry on 127.0.0.1:46969 in 224 ms
Jan 31, 2014 9:16:27 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1393 ms
Jan 31, 2014 9:16:27 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 31, 2014 9:16:27 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: VMware vFabric tc Runtime 2.9.3.RELEASE/7.0.42.A.RELEASE
Jan 31, 2014 9:16:27 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\Program Files\Spring Toolsuite\vfabric-tc-server-developer-2.9.3.RELEASE\base-instance\conf\Catalina\localhost\ContactManagement.xml
Jan 31, 2014 9:16:27 PM org.apache.catalina.startup.SetContextPropertiesRule begin
WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ContactManagement' did not find a matching property.
Jan 31, 2014 9:16:27 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Program Files\Spring Toolsuite\vfabric-tc-server-developer-2.9.3.RELEASE\base-instance\wtpwebapps\ContactManagement\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Jan 31, 2014 9:16:30 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Jan 31, 2014 9:16:30 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'spring'
[localhost-startStop-1] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'spring': initialization started
[localhost-startStop-1] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'spring-servlet': startup date [Fri Jan 31 21:16:30 EST 2014]; root of context hierarchy
[localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
[localhost-startStop-1] INFO org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from ServletContext resource [/WEB-INF/jdbc.properties]
[localhost-startStop-1] INFO org.springframework.jdbc.datasource.DriverManagerDataSource - Loaded JDBC driver: oracle.jdbc.OracleDriver
[localhost-startStop-1] INFO org.springframework.web.servlet.view.tiles2.TilesConfigurer - TilesConfigurer: adding definitions [/WEB-INF/tiles.xml]
[localhost-startStop-1] INFO org.apache.tiles.context.AbstractTilesApplicationContextFactory - Initializing Tiles2 application context. . .
[localhost-startStop-1] INFO org.apache.tiles.context.AbstractTilesApplicationContextFactory - Finished initializing Tiles2 application context.
[localhost-startStop-1] INFO org.apache.tiles.access.TilesAccess - Publishing TilesContext for context: org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory$SpringWildcardServletTilesApplicationContext
[localhost-startStop-1] INFO org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
2014-01-31 21:01:01,513 INFO [org.hibernate.tool.hbm2ddl.SchemaValidator] - <HHH000229: Running schema validator>
[...Database Validation...]
[localhost-startStop-1] INFO org.springframework.orm.hibernate4.HibernateTransactionManager - Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@1ca09d2] of Hibernate SessionFactory for HibernateTransactionManager
[localhost-startStop-1] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'spring': initialization completed in 11998 ms
Jan 31, 2014 9:16:42 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Spring Toolsuite\vfabric-tc-server-developer-2.9.3.RELEASE\base-instance\webapps\manager
Jan 31, 2014 9:16:42 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Spring Toolsuite\vfabric-tc-server-developer-2.9.3.RELEASE\base-instance\webapps\ROOT
Jan 31, 2014 9:16:42 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-48080"]
Jan 31, 2014 9:16:42 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 15126 ms
当我点击页面时,会出现以下内容:
[tomcat-http--3] WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/ContactManagement/contact] in DispatcherServlet with name 'spring'
编辑:我在没有mvc资源标签的情况下运行它,它在日志中提出了这些额外的行(让我觉得由于某种原因,当我包含资源标签时它不会映射控制器):
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addressType] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addressType.*] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addressType/] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addressType/.*] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addressType/add] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addressType/add.*] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addressType/add/] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addressType/delete/{addressTypeId}] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addressType/delete/{addressTypeId}.*] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addressType/delete/{addressTypeId}/] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addresstype] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addresstype.*] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addresstype/] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addresstype/.*] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addresstype/add] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addresstype/add.*] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addresstype/add/] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addresstype/delete/{addressTypeId}] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addresstype/delete/{addressTypeId}.*] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/addresstype/delete/{addressTypeId}/] onto handler 'addressTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/contact] onto handler 'contactController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/contact.*] onto handler 'contactController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/contact/] onto handler 'contactController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/contact/.*] onto handler 'contactController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/country] onto handler 'countryController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/country.*] onto handler 'countryController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/country/] onto handler 'countryController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/country/.*] onto handler 'countryController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/country/add] onto handler 'countryController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/country/add.*] onto handler 'countryController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/country/add/] onto handler 'countryController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/country/delete/{countryId}] onto handler 'countryController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/country/delete/{countryId}.*] onto handler 'countryController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/country/delete/{countryId}/] onto handler 'countryController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/emailtype] onto handler 'emailTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/emailtype.*] onto handler 'emailTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/emailtype/] onto handler 'emailTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/emailtype/.*] onto handler 'emailTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/emailtype/delete/{emailTypeId}] onto handler 'emailTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/emailtype/delete/{emailTypeId}.*] onto handler 'emailTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/emailtype/delete/{emailTypeId}/] onto handler 'emailTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/emailtype/add] onto handler 'emailTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/emailtype/add.*] onto handler 'emailTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/emailtype/add/] onto handler 'emailTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/phonetype] onto handler 'phoneTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/phonetype.*] onto handler 'phoneTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/phonetype/] onto handler 'phoneTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/phonetype/.*] onto handler 'phoneTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/phonetype/delete/{phoneTypeId}] onto handler 'phoneTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/phonetype/delete/{phoneTypeId}.*] onto handler 'phoneTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/phonetype/delete/{phoneTypeId}/] onto handler 'phoneTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/phonetype/add] onto handler 'phoneTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/phonetype/add.*] onto handler 'phoneTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/phonetype/add/] onto handler 'phoneTypeController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/salutation] onto handler 'salutationController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/salutation.*] onto handler 'salutationController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/salutation/] onto handler 'salutationController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/salutation/add] onto handler 'salutationController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/salutation/add.*] onto handler 'salutationController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/salutation/add/] onto handler 'salutationController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/salutation/delete/{salutationId}] onto handler 'salutationController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/salutation/delete/{salutationId}.*] onto handler 'salutationController'
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/salutation/delete/{salutationId}/] onto handler 'salutationController'