Java Rest Web服务显示名称 [英] Java rest webservice display name

查看:57
本文介绍了Java Rest Web服务显示名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始构建自己的其余Web服务,并且首先阅读了这个出色的教程: http://www.vogella.com/articles/REST/article.html#first_project

I've just started building my own rest webservice and I started off by going through this excellent tutorial: http://www.vogella.com/articles/REST/article.html#first_project

但是,有些事情我不太了解.它与服务的路径有关.

However there is something that I don't quite understand. It has to do with the path to the service.

hello资源的路径现在是这样:

The path is now this for the hello resource:

http://localhost:8080/de.vogella.jersey.first/rest/hello

这是本教程的默认设置.

This is default from the tutorial.

但是我想将其更改为更方便的链接,例如:

However i would like to change this to a more convenient link, for example like this:

http://localhost:8080/mywebservice/resources/hello

我尝试将web.xml更改为以下内容:

I change the web.xml to the following as a try to achieve it:

<?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>mywebservice</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>de.vogella.jersey.first</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/resources/*</url-pattern>
  </servlet-mapping>
</web-app> 

我更改了显示名称和url模式,但没有任何效果.尽管可以从旧路径中检索它,但我无法使用所需的路径来获得资源.

I changed the display name and the url-pattern but it has no effect. I cant get to the resource using the path I want it to be, though I can retrieve it from the old path.

那是为什么?来自web.xml的显示名称与此无关吗?

Why is that? Does the displayname from the web.xml got nothing to do with this?

推荐答案

您正在更改Webapp的上下文名称.如果以战争(Webapp存档)的形式进行部署,则战争的名称将为上下文名称.

You are changing the context name of the Webapp. If you're deploying it in the form of a war (webapp archive), the name of the war would be the context name.

在下面的示例中,您将使用该名称创建一个Dynamic Web项目.您必须适当地重命名.

In the example you're following, you're creating a Dynamic Web project with that name. You'll have to rename it suitably.

这篇关于Java Rest Web服务显示名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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