0

嗨,我创建了简单的 RESTful Web 服务并使用 JSON 进行响应和存储信息。当我在 tomcat 7.0 中运行该服务时,我在浏览器中遇到 404 错误

PLS 帮我修复错误

服务等级

package com.login.service;

import javax.ws.rs.Consumes;

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

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

//Path Reference to access this interface
@Path("/Sample")
public class OrdersService {


        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
11Processor.java:1009)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:589)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoin
t.java:312)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Returning the Response
4

1 回答 1

1

问题在这里:

JSONObject userDetails = null;
try 
{
   userDetails.put("firstname", "Jagathesewaren");

您正在调用put方法null。初始化userDetails对象

JSONObject userDetails = new JSONObject();
try 
{
   userDetails.put("firstname", "Jagathesewaren");
于 2013-10-25T06:06:58.057 回答