这是我的调度程序文件。我已经为schema / 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());
}
}
答案 0 :(得分:0)
<mvc:resources mapping="/resources/**" location="/resources/static/" />
此标记基本上表示如果URI中的路径以&#34; / resources /&#34开头;然后返回位于&#34; / resources / static /&#34;
中的文件检查您的文件(图片,css等)是否位于<your_webapp_root>/resources/static/
编辑:
我还注意到您在名称空间声明中使用了不同的版本:
spring-mvc-3.0.xsd
spring-beans-2.5.xsd
spring-context-2.5.xsd
检查您的依赖项并使用正确的版本