Web services 使用RestFul Web服务时出错
我已经创建了一个web服务-Web services 使用RestFul Web服务时出错,web-services,Web Services,我已经创建了一个web服务- @Path("/info") public class RestFulService { @GET @Produces(MediaType.TEXT_PLAIN) public String getPlain() { return " Web Service created"; } } 当我通过localhost浏览器访问时,正在呈现“Web服务已创建” 但当我试图通过另一个应用程序使用此web服务时,我得到了404错误代码-“线程“main”java.l
@Path("/info")
public class RestFulService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getPlain()
{
return " Web Service created";
}
}
当我通过localhost浏览器访问时,正在呈现“Web服务已创建”
但当我试图通过另一个应用程序使用此web服务时,我得到了404错误代码-“线程“main”java.lang.RuntimeException:Failed:HTTP错误代码:404
位于restcummer.main(restcummer.java:28)
"
RestConsumer.java中的代码-
public static void main(String[] args) {
try {
String uri = "http://localhost:8080/RestFul/rest/info";
URL url = new URL(uri);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", MediaType.TEXT_PLAIN);
conn.connect();
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
任何人都可以建议所需的更改。这是Eclipse中的一个基本设置问题。请参阅6:54的Youtube链接
它提供了一个逐步纠正相同问题的指南。希望这有帮助我想你忘记添加链接了