我试图通过创建动态Web项目从头开始构建一个简单的Dispatcher Servlet示例。
这些是我的文件。
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>flightReservation</display-name>
<servlet>
<servlet-name>FlightReservation</servlet-name>
<servlet-class>com.springfrawework.web.servlet.DispatcherSevlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FlightReservation</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
FlightReservation-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.practice.sfw.flight.reservation.controllers" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.html</value>
</property>
</bean>
</beans>
BasicController.java
package com.practice.sfw.flight.reservation.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/basic")
public class BasicController {
@RequestMapping(method=RequestMethod.GET)
public String getHello() {
return "basic";
}
}
basic.html
<html>
<body>
<h2>Hello from parallel universe</h2>
</body>
</html>
xml和html文件放在webapp / WEB-INF下
Maven构建和安装均成功。
但是,当我访问
http://localhost:8080/FlightReservation/basic我得到一个The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.