2017-05-17 20 views
0

Javaで安らかなWebサービスを作成しようとしています。私はそれを実行しようとしているときはいつも私は404エラーを取得していると私は理由を把握することができません!JavaでRestful Webサービスを実行すると404エラーが発生する

これはJavaTPointです。

これは私のプロジェクトはlike-

の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を

です私は対応 -

次取得しています210

<!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> 

enter image description here

誰も私が間違ってここにやっているものを指摘することはできますか?任意の助けが理解されるであろう。..

+1

あなたはhref = http:// localhost:8080/rest/files/txtを試すことができますか?あなたがポート8080であなたのローカルサーバーを稼働していると仮定しています –

+0

ありがとう..それは働いた – ValarDohaeris

答えて

1

をあなたは完全なパスを指定する必要がありますあなたのAPIに

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

ええ...それは働いた!ありがとう – ValarDohaeris

+0

喜んで私は助けることができた、あなたの問題を解決したら答えを受け入れてください –

関連する問題