如何在Jersey容器中配置欢迎文件(HTML / JSP) [英] How to configure welcome file (HTML/JSP) in Jersey container

查看:151
本文介绍了如何在Jersey容器中配置欢迎文件(HTML / JSP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jersey RESTful Web服务项目。我已经在 web.xml 中配置了Jersey容器,一切正常。

I have a Jersey RESTful web service project. I have configured the Jersey container in the web.xml and everything works fine.

在同一个项目中,我引入了一个HTML页面,包含在< welcome-file-list> 中,以处理其他一些非REST请求。但是当我访问URL时,不显示欢迎文件。

In the same project, I have introduced one HTML page and included in the <welcome-file-list> to handle some other non-REST request. But when I am accessing the URL, the welcome file is not displayed.

我在 web.xml 中评论Jersey容器配置并部署后应用程序,这次我可以访问欢迎文件。

After I commented the Jersey container configuration in web.xml and deployed the application, this time I am able to access the welcome file.

使用Tomcat 7,JDK 7,Jersey 2.2和Eclipse Juno。 Jersey配置后如何使欢迎文件正常工作? Jersey有没有限制,或者我需要以不同的方式配置才能实现这一点吗?

Am using Tomcat 7, JDK 7, Jersey 2.2 and Eclipse Juno. How to make the welcome file working when Jersey has configured? Is there any limitations with Jersey or do I need configure in different way to achieve this?

我的 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>My Service</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>com.my.rest.service</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>    
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
 </servlet-mapping>      
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file> 
  </welcome-file-list>
</web-app>


推荐答案

<?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>com.webservice.services</display-name>
    <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.webservice.services</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/service/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>



尝试使用上面给出的不同路径的URL模式(/ service / * )用于REST。服务器启动时,它可以工作并欢迎文件显示。


Try URL pattern with different path like given above (/service/*) for REST. It works and welcome file displays when server starts.

这篇关于如何在Jersey容器中配置欢迎文件(HTML / JSP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆