Java Spring MVC多servlet(Jersey、Dispatcher)问题

Java Spring MVC多servlet(Jersey、Dispatcher)问题,java,web-services,spring,spring-mvc,jersey,Java,Web Services,Spring,Spring Mvc,Jersey,我的页面有一个DispatcherServlet,Jersey Web服务有一个ServletContainer现在,没有页面呈现(404),但服务工作正常。如何将它们同时运行? 我看到这个线程似乎处理了一个类似的问题,尽管这是关于CXF的,所以我不确定它有多重要 我还尝试使用一个单独的Jersey-servlet.xml文件,但这使页面和服务都停止工作。真的不知道从这一点上走到哪里,非常感谢任何帮助 web.xml: <?xml version="1.0" encoding="UT

我的页面有一个DispatcherServlet,Jersey Web服务有一个ServletContainer现在,没有页面呈现(404),但服务工作正常。如何将它们同时运行?

我看到这个线程似乎处理了一个类似的问题,尽管这是关于CXF的,所以我不确定它有多重要

我还尝试使用一个单独的Jersey-servlet.xml文件,但这使页面和服务都停止工作。真的不知道从这一点上走到哪里,非常感谢任何帮助

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>HSRMVC</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>HSR</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>HSR</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>se.hsr.services</param-name>
      <param-value>HSRMVC</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

HSRMVC
index.jsp
高铁
org.springframework.web.servlet.DispatcherServlet
高铁
*.html
泽西岛休息服务
com.sun.jersey.spi.container.servlet.ServletContainer
东南高铁服务
HSRMVC
泽西岛休息服务
/*
HSR-sevlet.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.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">


    <mvc:annotation-driven />
    <context:component-scan
        base-package="se.hsr.web"/>

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
</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>HSRMVC</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>HSR</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>HSR</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
    /resources/applicationContext.xml
    /WEB-INF/service-beans.xml
  </param-value>
    </context-param>

    <servlet>
        <servlet-name>service-beans</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>se.hsr.services</param-name>
            <param-value>HSRMVC</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>service-beans</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

HSRMVC
index.jsp
高铁
org.springframework.web.servlet.DispatcherServlet
1.
高铁
*.html
上下文配置位置
/资源/applicationContext.xml
/WEB-INF/service-beans.xml
服务豆
com.sun.jersey.spi.container.servlet.ServletContainer
东南高铁服务
HSRMVC
2.
服务豆
/*
与您的场景相关

您也可以尝试使用。不过,这并不完全是为了这个目的。(它用于静态资源)


同时检查并解决问题。

我解决了问题

这就是我的新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>HSRMVC</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext.xml
        /WEB-INF/HSR-service-beans.xml
  </param-value>
    </context-param>

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

    <servlet>
        <servlet-name>HSR</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>HSR</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>HSR-service</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>se.hsr.services</param-name>
            <param-value>HSRMVC</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>HSR-service</servlet-name>
        <url-pattern>/service/*</url-pattern>
    </servlet-mapping>
</web-app>

HSRMVC
index.jsp
上下文配置位置
classpath*:applicationContext.xml
/WEB-INF/HSR-service-beans.xml
org.springframework.web.context.ContextLoaderListener
高铁
org.springframework.web.servlet.DispatcherServlet
1.
高铁
*.html
高铁服务
com.sun.jersey.spi.container.servlet.ServletContainer
东南高铁服务
HSRMVC
2.
高铁服务
/服务/*

“没有页面正在呈现(404),但服务工作正常”。。。这是什么意思?这意味着当我指向localhost/login.hmtl时,我得到一个404错误。当我写localhost/service/emil时,我会看到一个显示我名字的页面。谢谢你的回复。我阅读了您链接到的资源,但仍然不太了解如何使其工作。我尝试编辑我的web.xml(请参见originalpost),但问题仍然与以前一样存在。
classpath*:applicationContext.xml
如何工作?您的servlet的上下文配置文件的名称是什么<代码>为父上下文提供位置,父上下文是所有servlet的位置,还是不是?嗨,Mikhail。对不起,但是因为这是五年前的事了,老实说,我几乎记不起这件事了。希望其他人能够回答这个问题!