我正在尝试设置一个Spring MVC项目。我添加了一个调度程序servlet,一个jsp并设置了web.xml文件。但我不断
WARN org.springframework.web.servlet.PageNotFound-在DispatcherServlet中,名称为“ HelloWeb”的URI [/safesite/WEB-INF/jsp/hello.jsp]的HTTP请求未找到映射
这是我的web.xml
... <context-param> <description>Vaadin production mode</description> <param-name>productionMode</param-name> <param-value>true</param-value> </context-param> <!-- To load the Spring context --> <listener> <listener-class>org.activiti.explorer.servlet.WebConfigurer</listener-class> </listener> <!-- To allow session-scoped beans in Spring --> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <filter> <filter-name>UIFilter</filter-name> <filter-class>org.activiti.explorer.filter.ExplorerFilter</filter-class> </filter> <filter> <filter-name>JSONPFilter</filter-name> <filter-class>org.activiti.explorer.servlet.JsonpCallbackFilter</filter-class> </filter> <filter-mapping> <filter-name>UIFilter</filter-name> <url-pattern>/o/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>JSONPFilter</filter-name> <url-pattern>/service/*</url-pattern> </filter-mapping> <servlet> <servlet-name>Vaadin Application Servlet</servlet-name> <servlet-class>org.activiti.explorer.servlet.ExplorerApplicationServlet</servlet-class> <init-param> <param-name>widgetset</param-name> <param-value>org.activiti.explorer.CustomWidgetset</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Vaadin Application Servlet</servlet-name> <url-pattern>/ui/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Vaadin Application Servlet</servlet-name> <url-pattern>/VAADIN/*</url-pattern> </servlet-mapping> <servlet> <servlet-name>HelloWeb</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>HelloWeb</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping> <!-- Session timeout on one day --> <session-config> <session-timeout>480</session-timeout> </session-config>
这是我的HelloWeb-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans" 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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="org.activiti.explorer.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/jsp/" /> <property name="suffix" value=".jsp" /> </bean>
我的HelloController
package org.activiti.explorer.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; /** * * @author Fionn */ @Controller public class HelloController { @RequestMapping("/hello") public ModelAndView helloWorld() { String message = "<br><div align='center'>" + "<h3>********** Hello World, Spring MVC Tutorial</h3>This message is comming from CrunchifyHelloWorld.java **********<br><br>"; return new ModelAndView("hello", "message", message); } }
而我的hello.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@page trimDirectiveWhitespaces="true" %> <!DOCTYPE html> <html> <head> <title>Hello Spring MVC</title> </head> <body>
我无法弄清楚这一点,因此将不胜感激。
您似乎想念了 <mvc:annotation-driven />
<mvc:annotation-driven />
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- Enables the Spring MVC @Controller programming model --> <mvc:annotation-driven /> <context:component-scan base-package="org.activiti.explorer.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/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
请注意,我已经从xsd文件中删除了该版本,这意味着它将使用您jar文件中的模式(如果不兼容,将会出现验证错误)
@Nikolay发表评论后,我还注意到您的映射中存在错误(请注意,您仍然需要注释驱动的元素),您应该将控制器中的映射更改为
@RequestMapping("/hello.jsp")
并通过访问
/safesite/hello.jsp
或者 ,更常见的是,将servlet映射更改为
<servlet-mapping> <servlet-name>HelloWeb</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
和访问,如Nikolay所说 /safesite/hello
/safesite/hello