简体   繁体   English

在apache localhost:8080中运行应用程序

[英]Run application in apache localhost:8080

I have to run java URL="http://localhost:8080/RESTfulExample/rest/json/metallica/get" on Apache Tomcat but i am getting 404 Error. 我必须在Apache Tomcat上运行java URL =“ http:// localhost:8080 / RESTfulExample / rest / json / metallica / get”,但我遇到404错误。 i want to get json response so what am i doing? 我想得到json响应,所以我在做什么?

@Path("/json/metallica")
public class JSONService {

    @GET
    @Path("/get")
    @Produces(MediaType.APPLICATION_JSON)
    public Track getTrackInJSON() {

        Track track = new Track();
        track.setTitle("Enter Sandman");
        track.setSinger("Metallica");

        return track;

    }

public class NetClientGet {


    public static void main(String[] args) {

        try {

            URL url = new URL(
                    "http://localhost:8080/RESTfulExample/rest/json/metallica/get");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "application/json");



            BufferedReader br = new BufferedReader(new InputStreamReader(
                    (conn.getInputStream())));

            String output;
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {

                System.out.println(output);
            }

            conn.disconnect();

        } catch (MalformedURLException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();

        }

    }

}

Exception : 例外情况:

java.lang.RuntimeException: Failed : HTTP error code : 404 at com.mkyong.client.JerseyClientPost.main(JerseyClientPost.java:24) java.lang.RuntimeException:失败:HTTP错误代码:com.mkyong.client.JerseyClientPost.main(JerseyClientPost.java:24)上的404

Web.xml : Web.xml:

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Restful Web Application</display-name>

    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.mkyong.rest</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/</url-pattern>
    </servlet-mapping>

</web-app>

Your questions shows no indication of using /RESTfulExample/rest as base path. 您的问题没有表明使用/RESTfulExample/rest作为基本路径。
So, assuming the name of the application is RESTfulExample it seems you're serving this path: 因此,假设应用程序的名称是RESTfulExample ,似乎您正在使用以下路径:
/RESTfulExample/json/metallica/get

Also, you should have a compilation error from the two ** in your code: 另外,您应该在代码中的两个**处出现编译错误:
**track.setTitle("Enter Sandman");

暂无
暂无

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

相关问题 在localhost:8080上运行Selenium Webdriver - Run selenium webdriver on localhost:8080 如何仅使用localhost:8080 address运行servlet应用程序。这意味着我不想使用任何url模式 - how to run a servlet application with only localhost:8080 address.that means i dont want to any url patterns Apache tomcat域localhost或其他:8080,如何找到? - Apache tomcat domain localhost or other :8080 ,how to find that? 使用基本目录运行 Spring Boot 项目 - localhost:8080/demo/ - Run Spring Boot Project with base directory - localhost:8080/demo/ Java Jetty Maven Websocket应用程序在localhost:8080上运行 - java jetty Maven websocket application runs on localhost:8080 无法从 eclipse springboot 应用程序访问 localhost:8080 - Unable to access localhost:8080 from eclipse springboot application Tomcat服务器上的Intellij Web应用程序显示http:// localhost:8080 / index.jsp而不是http:// localhost:8080 / myapp / index.jsp - Intellij web application on tomcat server shows http://localhost:8080/index.jsp instead of http://localhost:8080/myapp/index.jsp localhost 4848,8080问题 - localhost 4848, 8080 problem Apache Tomcat 在 localhost:8080 显示一个已经制作的 WAR 文件而不是主页 - Apache Tomcat is showing an already made WAR file instead of the home page at localhost:8080 o.apache.coyote.http11.Http11Processor 处理请求错误 | 打开 localhost:8080 时 - o.apache.coyote.http11.Http11Processor Error processing request | while opening localhost:8080
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM