gpt4 book ai didi

java - Restful Webservice 不响应

转载 作者:行者123 更新时间:2023-11-29 05:33:09 26 4
gpt4 key购买 nike

我是网络服务编程的新手,遇到了麻烦。在网上搜索了两天后,我完全感到困惑,我的示例没有向我提供任何数据。

我想编写一个应该在 tomcat 7 或 glassfish 4 上运行的 restful web 服务。

这是我的代码:

SimpleService.class

@Path("say")
public class SimpleService {

@Path("hello")
@GET
public String doGreet() {
return "Hello Stranger, the time is "+ new Date();
}
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>test002</display-name>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/you/*</url-pattern>
</servlet-mapping>
</web-app>

http.//localhost:8070/test002/you/say/hello 上的请求得到 404。

最佳答案

也许从头开始是最明智的:https://jersey.java.net/documentation/latest/getting-started.html如果 Maven 不是一个选项,无论如何都要创建 Maven 项目并将其加载到 Eclipse 中。将类路径设置和“maven 依赖项”复制到您自己的项目中。

如果您弄清楚哪里出了问题,也许可以将其张贴在这里,以便其他人受益。

关于java - Restful Webservice 不响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20418532/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com