Redian新闻
>
问个RESTful的问题,简单的hello显示404错误
avatar
j*y
2
刚开始学REST, 没有用maven(不会)。新下载的jersey。请教是哪里有问题呢。
代码如下:
Java code:
package com.testrest.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
// Plain old Java Object it does not extend as class or implements
// an interface
// The class registers its methods for the HTTP GET request using the @GET
annotation.
// Using the @Produces annotation, it defines that it can deliver several
MIME types,
// text, XML and HTML.
// The browser requests per default the HTML MIME type.
//Sets the path to base URL + /hello
@Path("/hello1")
public class Hello {
// This method is called if TEXT_PLAIN is request
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "" + " Hello Jersey" + "";
}
// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return " " + "" + "Hello Jersey" + ""
+ "

" + "Hello Jersey" + "

" + " ";
}
}
web.xml

Jersey REST Service
org.glassfish.jersy.servlet.ServletContainerclass>

jersey.config.server.provider.packages
com.testrest.rest

1


Jersey REST Service
/rest/*
avatar
w*z
3
404 is the resource not found. Check your URL.
avatar
j*y
4
谢谢,但不是url的问题。看了一下log,说是
java.lang.ClassNotFoundException:org.glassfish.jersy.servlet.
ServletContainer
但是类库文件 jersey-servlet-container-core.jar 就在WEB-INF/lib/下。
不知道为什么在deploy的时候没有识别到。
求助!

【在 w**z 的大作中提到】
: 404 is the resource not found. Check your URL.
avatar
w*z
5
不熟glassfish, pretty sure jar files have to be deployed to the glassfish
app server
classpath.

【在 j****y 的大作中提到】
: 谢谢,但不是url的问题。看了一下log,说是
: java.lang.ClassNotFoundException:org.glassfish.jersy.servlet.
: ServletContainer
: 但是类库文件 jersey-servlet-container-core.jar 就在WEB-INF/lib/下。
: 不知道为什么在deploy的时候没有识别到。
: 求助!

avatar
g*g
6
Instead of trying to figure out what's wrong, take a built helloworld war
and drop it in tomcat, call it a day.

【在 j****y 的大作中提到】
: 刚开始学REST, 没有用maven(不会)。新下载的jersey。请教是哪里有问题呢。
: 代码如下:
: Java code:
: package com.testrest.rest;
: import javax.ws.rs.GET;
: import javax.ws.rs.Path;
: import javax.ws.rs.Produces;
: import javax.ws.rs.core.MediaType;
: // Plain old Java Object it does not extend as class or implements
: // an interface

avatar
d*i
7
Are you using Jersey 1.17 or 2.2? Not sure about 2.2. But in Jersey 1.17,
you should set up your web.xml file as:

Jersey REST Service
com.sun.jersey.spi.container.servlet.ServletContainerservlet-
class>

com.sun.jersey.config.property.packages
com.testrest.rest

1

This works fine for Jersey 1.17.

【在 j****y 的大作中提到】
: 刚开始学REST, 没有用maven(不会)。新下载的jersey。请教是哪里有问题呢。
: 代码如下:
: Java code:
: package com.testrest.rest;
: import javax.ws.rs.GET;
: import javax.ws.rs.Path;
: import javax.ws.rs.Produces;
: import javax.ws.rs.core.MediaType;
: // Plain old Java Object it does not extend as class or implements
: // an interface

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。