English 中文(简体)
玻璃鱼服务器显示Error 404, 位于应找到该页面的途中
原标题:Glassfish server showing Error 404, on the path where the page should be found

I am working on a web app using Intellij and Glassfish server. But, it is showing error 404, page not found. Specifically:

HTTP Status 404 - Not Found

type Status report

messageNot Found

descriptionThe requested resource is not available.

GlassFish Server Open Source Edition 4.1.1

我无法理解为什么出现这种情况。 我正在格拉斯这样做。

我先使用<代码>web.xml,然后扩充<代码>Application,但在这两种情况下结果相同。

我从关于SO的类似问题中尝试了解决办法,但没有一个办法奏效。

这是《根基资源法典》:

package com.pd.jersey.jaxb;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/")
class RootResource {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello(){
        return "Hello";
    }
}

这是托多资源:

package com.pd.jersey.jaxb;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/todo")
public class TodoResource {
    @GET
    @Produces({MediaType.APPLICATION_XML})
    public Todo getXML() {
        Todo todo = new Todo();
        todo.setSummary("Application XML Todo Summary");
        todo.setDescription("Application XML Todo Description");
        return todo;
    }

    // This method is called if JSON is requested
    @GET
    @Produces({MediaType.APPLICATION_JSON})
    public Todo getJSON() {
        Todo todo = new Todo();
        todo.setSummary("Application JSON Todo Summary");
        todo.setDescription("Application JSON Todo Description");
        return todo;
    }

    // This can be used to test the integration with the browser
    @GET
    @Produces({ MediaType.TEXT_XML })
    public Todo getHTML() {
        Todo todo = new Todo();
        todo.setSummary("XML Todo Summary");
        todo.setDescription("XML Todo Description");
        return todo;
    }
}

这是适用法:

package com.pd.jersey.jaxb;

import javafx.application.Application;
import javafx.stage.Stage;

import javax.ws.rs.ApplicationPath;
import java.util.HashSet;
import java.util.Set;

@ApplicationPath("/rest")
public class RestApplication extends Application {
    // All request scoped resources and providers
    public Set<Class<?>> getClasses() {
        Set<Class<?>> classes = new HashSet<>();
        classes.add(TodoResource.class);
        return classes;
    }

    // all singleton resources and providers
    public Set<Object> getSingletons() {
        Set<Object> singletons = new HashSet<>();
        return singletons;
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

    }
}

这是我的组合的总结:

“run-confration”/

我看不到什么是错的。 我感谢任何帮助。

问题回答

You re overriding the wrong Application. The one you re using is for JavaFX, which is for making graphical user interfaces. You need to extend javax.ws.rs.core.Application.

您提出的问题表明,你为什么应当使用@Override 。 当你凌驾于一种方法之上时;因此,你知道你实际上凌驾于这一类方法之上(即:getClasses (getSingletons()。 请加入<条码>。 以上,您将看到,在<代码>应用<>代码/代码>的类别中,该代码没有一种方法。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签