Spring MVC中的简单映射

时间:2013-06-12 10:27:24

标签: spring spring-mvc

我有以下内容:

<?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/javaee"
   xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>FirstServlet</display-name>
<welcome-file-list>
      <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

<listener>
    <listener-class>org.vlad.firstservlet.ContextListener</listener-class>
  </listener> 

 <servlet>
<servlet-name>main</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/context.xml</param-value>
    </init-param>
   </servlet>

   <servlet-mapping>
    <servlet-name>main</servlet-name>
<url-pattern>/</url-pattern>
  </servlet-mapping>

</web-app>

@Controller
public class Servlet 
{
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String sayHello()
{
    return "hello";
}

@RequestMapping(value="/hello/ana", method = RequestMethod.GET)
public String secondaryHello()
{
    return "ana";

}

@RequestMapping(value="/", method = RequestMethod.GET)
public String sayDefault()
{
    return "default";

}
}

如果我把localhost:8080 / FirstServlet /你好,它的工作原理 如果我把localhost:8080 / FirstServlet / pello / ana它没有 如果我改变控制器直接将secondaryHello()映射到ana就可以了。

当它不起作用时,它会抱怨它无法找到ana.jsp

0 个答案:

没有答案