0

我正在使用 JBoss servlet 引擎中的 Java/Spring/Maven 并利用 MultiActionController 设置 REST api。

I want to do is to group requests to a Single controller例如: all /requestA goes to Controller a,具有针对不同请求的多种方法,例如 -/requestA/add.do goes to add-function

  • /requestA/delete.do goes to delete-function.

我一直在阅读 Spring 文档: http ://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch18s02.html 和 http://static.springsource.org /spring/docs/3.0.0.M3/spring-framework-reference/html/ch16s03.html#mvc-controller-multiaction

但是我在 xml 中的调度程序配置中遇到了一些问题。有谁知道如何在 Spring MVC 中实现这一点的好例子。

springapp-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
<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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean name="/test/*.do" class="org.test.TestControllerA" />
</beans>

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/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_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>springTest</display-name>

    <servlet>
        <servlet-name>springapp</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>springapp</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
</web-app>

和 Java 控制器

    public class TestControllerA extends MultiActionController {

    @RequestMapping("/TEST")
    public ModelAndView add(HttpServletRequest request, HttpServletResponse response) throws Exception {
    System.out.println("Test42");
    return new ModelAndView();
  }
}
4

1 回答 1

1

您缺少 servlet 映射

<servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

您的网址具有扩展名*.do,但未映射到springapp. 因此,将上述配置添加到您的web.xml

于 2013-03-05T12:39:10.040 回答