Spring Web Application - 请求的资源不可用

时间:2017-05-28 09:28:10

标签: java jsp spring-mvc tomcat web

我想请教您一些建议,我的简单教程弹簧网络应用程序示例可能出错。

我正在尝试通过此网址访问网站:

http://localhost:8084/SpringTutorial/hello

作为对此URL的响应,我从apache tomcat服务器获取HTTP 404 - 资源不可用。

项目文件夹结构的图像位于本文的底部。

以下是代码:

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
        <display-name>SpringTutorial</display-name>
        <servlet>
            <servlet-name>spring-dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/spring-dispatcher-servlet.xml</param-value>
            </init-param>

            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>spring-dispatcher</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    </web-app>

弹簧调度-servlet.xml中

<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?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"
   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">

    <!-- Scanning for anotation base classes (controllers) -->
    <context:component-scan base-package="com.controllers" /> 
    <!-- Using anotation based classes (controllers) -->
    <mvc:annotation-driven/>

    <bean id="viewResolver"
          class="org.springframeúwork.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />

</beans>

HelloController.java

package com.controllers;

import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.portlet.ModelAndView;

@Controller
public class HelloController {

    @RequestMapping(value="/hello", method = RequestMethod.POST)
    public ModelAndView sayHello(){
        ModelAndView hello = new ModelAndView("HelloPage");
        hello.addObject("message", "Welcome at first Spring web application");
        return hello;
    }        
}

HelloPage.jsp
显示message属性。 简单的HTML代码,如:

<html>
   <head>
   ...
   </head
   <body>
     <h2>${message}</h2>
   </body>
</html>

----------Here is the image of project folder hierarchy----------

0 个答案:

没有答案