简体   繁体   English

REST项目错误(Tomcat:HTTP错误404)

[英]REST project error (Tomcat: HTTP ERROR 404)

I just begin to learn java rest service. 我刚刚开始学习Java Rest服务。 I follow some of the website to build a Rest service but it seems like it keeps gave me the same error :'(. 我遵循一些网站来构建Rest服务,但似乎它一直给我同样的错误:'(。

Trust me! 相信我! I have tried to search stackoverflow and other forum for solutions but it seems like it doesn't work for me. 我试图在stackoverflow和其他论坛上搜索解决方案,但似乎对我不起作用。 The error keeps coming back to me. 错误不断回到我身边。

Project: I made Dynamic Web Project in version 4.9 and Tomcat 8.5 in eclipse. 项目:我在Eclipse中创建了4.9版的Dynamic Web Project和Tomcat 8.5。 Then I copy all the jars to WEB-INF/lib 然后我将所有罐子复制到WEB-INF / lib

Please check below screenshots for project details: 请检查以下屏幕截图以获取项目详细信息:

Server Details: 服务器详细信息:

enter image description here 在此处输入图片说明

Project Details: 项目详情:

enter image description here 在此处输入图片说明

WEB Content: 网页内容:

enter image description here 在此处输入图片说明

META-INF enter image description here META-INF 在此处输入图像描述

Code Details: 代码详细信息:

package com.firstproject;

import javax.ws.rs.*;


@Path("/")
public class Scoreservice {


    private static int WIN,LOSSES,TIES;


    @GET
    @Path("/score")
    @Produces("application/json")
    public String getScore() {
        String pattern =  "{ \"wins\":\"%s\", \"losses\":\"%s\", \"ties\": \"%s\"}";
            return String.format(pattern, WIN, LOSSES, TIES);
    }


    @PUT
    @Path("/score")
    @Produces("application/json")
    public String update(@QueryParam("WIN") int wins, 
                            @QueryParam("LOSSES") int losses, 
                            @QueryParam("TIES")   int ties) {
       Scoreservice.WIN   = wins;
       Scoreservice.TIES   = ties;
       Scoreservice.LOSSES = losses;
       String pattern = 
          "{ \"wins\":\"%s\", \"losses\":\"%s\", \"ties\": \"%s\"}";
       return String.format(pattern, WIN, LOSSES, TIES);   
    }



    @POST @Path("/scores/wins")
    @Produces("text/plain")
    public int increaseWin() {
        return ++WIN;   
    }


    @POST @Path("/scores/losses")
    @Produces("text/plain")
    public int increaseLosses() {
        return ++LOSSES;    
    }


    @POST @Path("/scores/ties")
    @Produces("text/plain")
    public int increaseTies() {
        return ++TIES;  
    }

    //GET METHOD

    @GET @Path("/scores/wins")
    @Produces("text/plain")
    public int getWin() {
        return WIN; 

    }

    @GET @Path("/scores/losses")
    @Produces("text/plain")
    public int getLosses() {
        return LOSSES;  
        }


    @GET @Path("/scores/ties")
    @Produces("text/plain")
    public int getTies() {
        return TIES;    
        }

}

Problems: 问题:

Upon completion of code, I tried to run it on server but it keeps gave me the same result which is the Http 404 erros (as per attached link below). 代码完成后,我尝试在服务器上运行它,但是它始终给我相同的结果,即Http 404错误(按照下面的附加链接)。

enter image description here 在此处输入图片说明

Console log: 控制台日志:

enter image description here enter image description here 在此处 输入图像描述在 此处 输入图像描述

I do not know what's wrong with the project and I swear that I really tried to search for results before I came here to ask for this question. 我不知道该项目出了什么问题,我发誓在来到这里提出这个问题之前,我真的试图搜索结果。 Hope you guys help me out and Thanks! 希望你们帮助我,谢谢!

Regarding your Console log, it seems that your webapp is not deployed yet even your tomcat is started in Eclipse. 关于控制台日志,似乎您的Web应用程序尚未部署,甚至在Eclipse中也启动了tomcat。

You can modify your Tomcat configuration in Eclipse by switching sever location to "Use tomcat installation"(check attached image). 您可以通过将服务器位置切换到“使用tomcat安装”(检查附件图像)来在Eclipse中修改Tomcat配置。 Currently, that option is disabled, you can remove your app from tomcat server, stop and clean tomcat server. 目前,该选项已禁用,您可以从tomcat服务器中删除您的应用,停止并清理tomcat服务器。 Then that option will be re-enabled. 然后,该选项将被重新启用。

Give a try and tell me what is going on. 试试看,告诉我怎么回事。

切换tomcat服务器位置

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

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