【发布时间】:2017-08-06 22:51:17
【问题描述】:
在 Eclipse 中我有 following Spring MVC project,但是当我在服务器上运行时,我在资源(图像、CSS、js...)的负载上遇到了问题。
我已经添加了mvc:resources mapping,但是当我运行jsp时,eclipse告诉我:
org.springframework.web.servlet.DispatcherServlet noHandlerFound 在名称为“dispacciatore”的 DispatcherServlet 中未找到 URI
[/ProgettoTecWeb/<c:url value=]的 HTTP 请求的映射
你有什么解决办法吗?谢谢!
web.xml
<web-app id = "WebApp_ID" version = "2.4"
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">
<display-name>Talent Show</display-name>
<servlet>
<servlet-name>dispacciatore</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispacciatore</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
dispacciatore-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"> <context:annotation-config />
<context:component-scan base-package="it.uniparthenope"/>
<!-- Vado a settare il package dove andrò a mettere la mia classe java
che farà da home Controller. -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:view-controller path="/" view-name="index"/>
<mvc:resources mapping="/resources/**" location="/resources/" cache-period="31556926"/>
<mvc:annotation-driven />
</beans>
index.jsp(如何调用资源)
<link href="<c:url value='/resources/assets/css/style.css"/>" rel="stylesheet">
...
<script src="<c:url value="/resources/assets/js/custom.js"/>"></script>
【问题讨论】:
标签: java spring eclipse jsp spring-mvc