404错误的解决方案使用json的restful Web服务

时间:2013-10-25 05:43:05

标签: java json web-services rest tomcat

您好我创建了简单的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

1 个答案:

答案 0 :(得分:1)

问题出在这里:

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

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

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