简体   繁体   English

Java Restful Service eclipse tomcat HTTP Error 404

[英]Java Restful Service eclipse tomcat HTTP Error 404

i try to keep up with a java rest service. 我试着跟上一个java休息服务。 So i found some tutorials, which explain always the same way. 所以我找到了一些教程,它们总是以相同的方式解释。 But i cant get this running :(. 但我不能让这个运行:(。

I made Dynamic Web Project in Version 2.5 and Tomcat 7.0 in eclipse. 我在版本2.5中创建了Dynamic Web Project,在eclipse中创建了Tomcat 7.0。 Then i load following jars to WEB-INF/lib 然后我将以下jar加载到WEB-INF / lib

在此输入图像描述

My Projectname is com.freespots.rest. 我的项目名是com.freespots.rest。 I created following web.xml 我创建了以下web.xml

在此输入图像描述

Ok now iam going to create the java-class right? 好的,我现在要创建java类吗? Well i did it Java Resources/src/com.freespots.rest.service: 我做了Java Resources / src / com.freespots.rest.service:

在此输入图像描述

If i start Tomcat and type url to my browser like localhost:8080/com.freespots.rest the Tomcat shows my index.html file. 如果我启动Tomcat并在我的浏览器中键入url,如localhost:8080 / com.freespots.rest,则Tomcat会显示我的index.html文件。 But if i go to url localhost:8080/com.freespots.rest/api/hello there is just a HTTP 404 Error: 但是,如果我去url localhost:8080 / com.freespots.rest / api / hello只有一个HTTP 404错误: 在此输入图像描述

Well iam new to Java Webdevelopment and i cant figure out my Problem. 我刚接触Java Webdevelopment,我无法弄清楚我的问题。 I hope some guy can explain my mistake. 我希望有些人可以解释我的错误。 Thanks in advance. 提前致谢。

You're using the old (1.x) Jersey configuration. 您正在使用旧的(1.x)Jersey配置。 In Jersey 2.x, the class namescpaces and property names have changed. 在Jersey 2.x中,类名称空间和属性名称已更改。 You should instead use 你应该改用

<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
    <param-name>jersey.config.server.provider.packages</param-name>
    ...

See other deployment options here 在此处查看其他部署选项

localhost:8080/com.freespots.rest this URL will run welcome page which is index.html as you said, and localhost:8080/com.freespots.rest/api/hello here no page found so 404 not found error. localhost:8080 / com.freespots.rest此URL将运行欢迎页面,如你所说的index.html, localhost:8080/com.freespots.rest/api/hello这里找不到页面,所以404找不到错误。 Try to put @Path("name") above method and call localhost:8080/com.freespots.rest/api/hello/name 尝试将@Path("name")放在方法上面并调用localhost:8080/com.freespots.rest/api/hello/name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM