簡體   English   中英

春季添加mvc:resources標簽

[英]Spring adding mvc:resources tag

這是我的調度程序文件。 我已經添加了架構/ mvc,內容及其對應位置的名稱空間...

現在,當我使用下面的xml運行我的應用程序時,找不到我的應用程序的頁面,但是當我刪除xmlns:mvc和resources標簽時,它的工作沒有任何問題...

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd
    ">


<context:component-scan base-package="com.school.controller" />

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
          <property name="prefix">
             <value>/WEB-INF/pages/</value>
          </property>
          <property name="suffix">
             <value>.jsp</value>
          </property>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/static/" />

網址http://localhost:8080/SchoolManagement/

web.xml中

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

Servlet-

package com.school.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.school.beans.Login;

@Controller
public class Logincontroller {
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView student() {
        return new ModelAndView("login", "loginform", new Login());
    }
}
<mvc:resources mapping="/resources/**" location="/resources/static/" />

該標簽基本上表示,如果URI中的路徑以“ / resources /”開頭,則返回位於“ / resources / static /”中的文件

檢查您的文件(圖片,css等)是否位於<your_webapp_root>/resources/static/

編輯:

我還注意到您在名稱空間聲明中使用了不同的版本:

spring-mvc-3.0.xsd
spring-beans-2.5.xsd
spring-context-2.5.xsd

檢查您的依賴關系並使用正確的版本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM