Я пытаюсь создать простой пример сервлет-диспетчера с нуля, создав динамический веб-проект.
Это мои файлы.
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.
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.