簡體   English   中英

在Java中運行Restful Web Service時遇到404錯誤

[英]Getting 404 error on running Restful web Service in java

我試圖在Java中創建一個寧靜的Web服務。 每當我嘗試運行它時,我都會收到404錯誤,並且我無法弄清原因!

我指的是JavaTPoint

這就是我的項目的樣子-

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"   
    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">  
     <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.javatpoint.rest</param-value>  
        </init-param>  
        <load-on-startup>1</load-on-startup>  
      </servlet>  
      <servlet-mapping>  
        <servlet-name>Jersey REST Service</servlet-name>  
        <url-pattern>/rest/*</url-pattern>  
      </servlet-mapping>  
    </web-app> 

FileDownloadService.java

package com.javatpoint.rest;

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

@Path("/files")
public class FileDownloadService {
    @GET
    @Path("/txt")
    @Produces(MediaType.TEXT_XML)
    public String getFile() {
        String response = null;
        response = "<?xml version='1.0'?><hello>Hello xml</hello>";
        return response;
    }
}

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <a href="rest/files/txt">Download Text File</a>
</body>
</html>

我正在關注回應-

在此處輸入圖片說明

任何人都可以指出我在這里做錯了嗎?任何幫助將不勝感激。

您需要指定api的完整路徑

<a href="[full path to your servlet container]/rest/files/txt">Download Text File</a>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM