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>
誰も私が間違ってここにやっているものを指摘することはできますか?任意の助けが理解されるであろう。..
あなたはhref = http:// localhost:8080/rest/files/txtを試すことができますか?あなたがポート8080であなたのローカルサーバーを稼働していると仮定しています –
ありがとう..それは働いた – ValarDohaeris