Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTTP状态404-在Spring MVC控制器中_Spring_Jsp_Spring Mvc - Fatal编程技术网

HTTP状态404-在Spring MVC控制器中

HTTP状态404-在Spring MVC控制器中,spring,jsp,spring-mvc,Spring,Jsp,Spring Mvc,我不熟悉spring框架。我正在从中处理一个,但收到以下错误: HTTP Status 404 - /AMController/index.jsp --------------------------- type Status report message /AMController/index.jsp description The requested resource is not available. -------------------------- Apache Tomc

我不熟悉spring框架。我正在从中处理一个,但收到以下错误:

 HTTP Status 404 - /AMController/index.jsp
 ---------------------------
 type Status report
 message /AMController/index.jsp
 description The requested resource is not available.
-------------------------- 
Apache Tomcat/6.0.44
控制器类

@Controller
@RequestMapping("/hello")
public class HelloController {

   @RequestMapping(method = RequestMethod.GET)
   public String printHello(ModelMap model) {
      model.addAttribute("message", "Hello Spring MVC Framework!");
      return "hello";
   }

}
和web.xml

        <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.4">
      <display-name>Spring MVC Application</display-name>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      <servlet>
        <servlet-name>AMController</servlet-name>
        <servlet-class>
                 org.springframework.web.servlet.DispatcherServlet
              </servlet-class>
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>/WEB-INF/AMController-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>AMController</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    </web-app>

SpringMVC应用程序
index.jsp
调幅控制器
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/AMController-servlet.xml
1.
调幅控制器
/
AMController-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"
   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">

    <mvc:annotation-driven/>
    <mvc:default-servlet-handler/>
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>

   <context:component-scan base-package="com.example.*" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/jsp/" />
      <property name="suffix" value=".jsp" />
   </bean> 
   <!-- 
    <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/" />
        <property name="suffix" value=".jsp" />
    </bean> -->

</beans>

/WEB-INF/jsp/hello.jsp

<html>
   <head>
   <title>Hello Spring MVC</title>
   </head>
   <body>
   <h2>${message}</h2>
   </body>
</html>

你好,Spring MVC
${message}
可能是我遗漏了一些我无法理解的东西。 请帮我解决这个问题

最诚挚的问候

HTTP状态404。 没有找到

首先,检查设置和路径

(servlet.xml)

您可以在浏览器中输入url

localhost:host/context路径,web应用程序项目名称/hello/print/hello

HTTP状态404。 没有找到

首先,检查设置和路径

(servlet.xml)

您可以在浏览器中输入url


localhost:host/context path,web应用项目名称/hello/print/hello

什么是上下文路径?什么是上下文路径?
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/jsp/" />
      <property name="suffix" value=".jsp" />
   </bean> 
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
@Controller
@RequestMapping("/hello")
public class HelloController {

   @RequestMapping(value = "/print/hello" ,method = RequestMethod.GET)
   public String printHello(ModelMap model) {
      model.addAttribute("message", "Hello Spring MVC Framework!");
      return "/hello";
   }
}