有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在java中运行Restful web服务时出现404错误

我正在尝试用java创建一个restful web服务。每当我试图运行它时,我都会遇到404错误,我无法找出原因

我指的是JavaTPoint

这就是我的项目的样子-

网络。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> 

文件下载服务。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;
    }
}

索引。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>

我得到以下回应-

enter image description here

有人能指出我做错了什么吗?任何帮助都将不胜感激


共 (0) 个答案