简体   繁体   English

Restful Web 服务问题 - HTTP 状态 404 - 请求的资源不可用

[英]Restful Web service issue - HTTP Status 404 - The requested resource is not available

I am trying one restful web service example so when I am going to hit url that time I am getting HTTP Status 404 - The requested resource is not available我正在尝试一个宁静的 Web 服务示例,所以当我要点击 url 时,我收到 HTTP 状态 404 - 请求的资源不可用

below are the detail of my code, if you want any other information let me know以下是我的代码的详细信息,如果您需要任何其他信息,请告诉我

Web.xml网页.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" 
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
   id="WebApp_ID" version="3.0">
   <display-name>User Management</display-name>
   <servlet>
      <servlet-name>Jersey RESTful Application</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.tutorialspoint</param-value>
         </init-param>
      </servlet>
   <servlet-mapping>
   <servlet-name>Jersey RESTful Application</servlet-name>
      <url-pattern>/rest/*</url-pattern>
   </servlet-mapping>  
</web-app>

Service class服务类

package com.tutorialspoint;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/UserService")
public class UserService {

   UserDao userDao = new UserDao();

   @GET
   @Path("/users")
   @Produces(MediaType.APPLICATION_XML)
   public List<User> getUsers(){
      return userDao.getAllUsers();
   }    
}

ALL jars所有罐子

在此处输入图片说明

Tomcat webapps Tomcat 网络应用程序

在此处输入图片说明

Obviously, your URL shoud be http://localhost:8080/UserManagement/rest/UserService/users .显然,您的 URL 应该是http://localhost:8080/UserManagement/rest/UserService/users

Also you can try to delete * in <url-pattern>/rest/*</url-pattern>您也可以尝试删除<url-pattern>/rest/*</url-pattern>

This issue has been resolved,此问题已得到解决,

Actually my web.xml was not on correct place that is why I was getting the "The requested resource is not available" .实际上,我的 web.xml 不在正确的位置,这就是为什么我收到“请求的资源不可用”的原因。 The file web.xml should be placed inside WEB-INF folder文件 web.xml 应该放在 WEB-INF 文件夹中

I had the same error.我有同样的错误。 I correct it with modifying the web.xml, when decalring the servlet.在对 servlet 进行贴标时,我通过修改 web.xml 来纠正它。

 <servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>org.webservice.messenger.ressources</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>

My package was declared :我的包裹被声明为:

 <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>org.webservice.messenger.messengers</param-value> </init-param>

while my classes were on package : org.webservice.messenger.ressources当我的课程在包上时:org.webservice.messenger.ressources

I hope it s clear now.我希望现在清楚了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM