0

我正在使用弹簧 MVC 和 GAE。我必须用一堆数据调用一个外部 URL。他们将结果返回给我,请致电 www.mystuff.com/results.jsp。我需要通过控制器重新路由,而不是显示 jsp 视图。如何更改调度程序 servlet 来做到这一点?

我的 web.xml 和 mvc-dispatcherservlet 和控制器注释一样非常普通。

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" version="2.5">

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    <filter>
        <filter-name>ObjectifyFilter</filter-name>
        <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ObjectifyFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

mvc 调度程序

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schem...-beans-3.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schem...ontext-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.hmt1.controller" />
    <mvc:annotation-driven />

    <bean
class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
        <property name="prefix">
            <value>/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

</beans>

我正在使用注释,所以控制器看起来像

@Controller
@RequestMapping("/mailandcontact")
public class MailAndContactController {
    @RequestMapping(value="/contact", method = RequestMethod.POST)
    public ModelAndView about(HttpServletRequest request, ModelMap model)  
            // do some sork
            //create the ModelAndView , stuff in the data and return i   
4

1 回答 1

0

servlet 映射

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

控制器

@Controller
@RequestMapping("/")
public class MailAndContactController {
    @RequestMapping(value="/results", method = RequestMethod.POST)
    public String handleResults(HttpServletRequest request, Model model)  {
        //Do stuff            
        return "results";
    }
}
于 2013-07-02T10:20:08.210 回答