我正在尝试在java中创建一个安静的Web服务。每当我点击调用Web服务的链接时,我会看到以下页面 -
我指的是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>
的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="localhost:9989/rest/files/txt">Download Text File</a>
</body>
</html>
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 msg="<?xml version='1.0'?>"
+ "<hello>AAAA</hello>";
return msg;
}
}
任何人都可以指出我在这里做错了吗?任何帮助都将受到赞赏..
答案 0 :(得分:1)