2017-03-15 104 views
-2

在Eclipse中我已经在following Spring MVC project,但是当我在服务器上运行,我对资源的负载已经问题(图像,CSS,JS ...) 。 我已经添加mvc:resources mapping,但是当我运行JSP,日食告诉我:Spring MVC的 - 没有找到HTTP请求中找到(资源)映射

org.springframework.web.servlet.DispatcherServlet noHandlerFound 没有映射的DispatcherServlet发现HTTP请求的URI与用[/ProgettoTecWeb/<c:url value=]名称 'dispacciatore'

你有什么解决办法吗?谢谢!

的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> 

回答

0

看起来你从index.jsp中调用资源有一个错字。这也可能是问题

注重引号

您正在呼吁这样

<link href="<c:url value='/resources/assets/css/style.css"/>" rel="stylesheet"> 

而不是

<link href="<c:url value="/resources/assets/css/style.css"/>" rel="stylesheet"> 

看看是否有帮助。 实际上,你可以给出路径,而不JSTL标记,它工作在春季

+0

实际上,你可以付出而不JSTL标签的路径,它工作得很好春 – BabyHulk

0

你需要为Controller类创建的软件包,使用注释RequestMapping到线到http映射。最后,使用扫描部件以指向该特定控制器包。它应该工作。

0
  1. 项目就好了 - >构建路径 - >配置构建路径 - >添加服务器运行时
  2. 修改Java版本运行最新
  3. Windown - >显示视图 - >问题 - >快速解决所有问题
相关问题