404 错误的解决方案 将 restful Web 服务与 json 结合使用



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

请帮助我修复错误

服务类

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

问题就在这里:

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

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

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

最新更新