2

与 DWR 集成时,我遇到了 spring MVC 映射问题。问题是,我不能让他们一起工作。我想在我的 jsp 中使用 dwr 服务,但是当 dwr 映射工作时,spring 不会,相反。

web.xml

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

    <display-name>Spring MVC Application</display-name>

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

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

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


    <listener>
        <listener-class>
            SpringListeners.MySessionListener
        </listener-class>
    </listener>
    <session-config>
        <session-timeout>1</session-timeout>
    </session-config>

</web-app>

mvc-调度程序-servler.xml

<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"
       xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr/spring-dwr-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <context:component-scan base-package="com.springapp.mvc"/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>


    <dwr:controller id="dwrController" debug="true">
        <dwr:config-param name="activeReverseAjaxEnabled" value="true"/>
        <dwr:config-param name="scriptCompressed" value="true"/>
        <dwr:config-param name="fileUploadMaxBytes" value="10485760"/>
        <dwr:config-param name="allowScriptTagRemoting" value="true"/>
    </dwr:controller>


    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="alwaysUseFullPath" value="true"/>
        <property name="mappings">
            <props>
                <prop key="/dwr/**/*">dwrController</prop>
            </props>
        </property>
    </bean>



    <bean id="Player" class="dwr.Player" scope="session">
        <dwr:remote javascript="Player">
            <!--<dwr:include method="" />-->
        </dwr:remote>
        <aop:scoped-proxy proxy-target-class="false"/>
    </bean>

</beans>

现在 dwr 在调试模式下工作,但所有其他 spring 映射都没有。当我删除

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="alwaysUseFullPath" value="true"/>
            <property name="mappings">
                <props>
                    <prop key="/dwr/**/*">dwrController</prop>
                </props>
            </property>
        </bean>

dwr 不起作用,但 spring 映射可以。这是我用于测试弹簧映射的控制器

@Controller
@RequestMapping("/")
public class HelloController {
    @RequestMapping(method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        System.out.println("agaga");
        model.addAttribute("message", "Hello world!");

        return "hello";
    }
}
4

0 回答 0