小编Kha*_*_it的帖子

Spring MVC中的延迟结果返回错误响应

我使用spring mvc 3.2.4和jquery 1.9.0进行长轮询.我的应用程序部署在Tomcat 7.0.42上.我的spring配置文件如下:

应用程序Web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee"   
  version="3.0">

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>app</servlet-name>

        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>

        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>

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

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

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

</web-app>
Run Code Online (Sandbox Code Playgroud)

Spring Configration 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:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd">
        <context:annotation-config/>
        <mvc:annotation-driven/>  
        <mvc:default-servlet-handler/>
        <context:component-scan base-package="com.webchat"/>
        <bean id="defferedResult" class="com.exp.DeferredResultContainer"></bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

发布数据的控制器看起来像

@RequestMapping(value = "/postComment", method = RequestMethod.POST)
public @ResponseBody String postComment(HttpServletRequest request) {
    deferredResultContainer.updateAllResults(request.getParameter("comment")); …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc

17
推荐指数
1
解决办法
2527
查看次数

标签 统计

java ×1

spring-mvc ×1