繁体   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