@PathParam = null

@PathParam = null

您好,我已经检查了很多帖子,但我还没有发现我遇到的问题。我的 PathParam 总是为空,谁能告诉我可能是什么问题

在接口中导入:

import javax.servlet.http.HttpServletRequest; 
import javax.ws.rs.PathParam; 
import javax.ws.rs.Produces; 
import javax.ws.rs.QueryParam; 
import javax.ws.rs.core.MediaType;

接口:

@RequestMapping(value="/unhash/{hash}", method = RequestMethod.GET)
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResponseBody
Token decryptToken(@PathParam("hash") String token, HttpServletRequest request) throws APIException;

和实施:

@Override
public Token decryptToken(String token, HttpServletRequest request) throws APIException {

我在这里没有发现任何异常,查询参数工作正常。有任何想法吗?我一头雾水。

您如何调用您的服务以及为什么要发送 HttpServletRequest 参数?我在没有 HttpServletRequest 的情况下使用 Jersey 实现了您的场景。我用 service/unhash/xxx 调用了服务。它工作正常。

@Path("/service")
public class MyFirstRestService implements Rest {

        @Override
        public Response decryptToken(String token) throws Exception {
        // TODO Auto-generated method stub
        String output="It is success-  Path Pram : "+ token;

        return Response.ok(output).build();
        }

Rest.class :

public  interface Rest {

        @GET
        @Path(value="/unhash/{hash}")
        @Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })

        Response decryptToken(@PathParam("hash") String token) throws Exception;

}

转到 http://www.javawebservice.com 了解更多信息和示例