Java @QueryParam取消绑定以获取请求参数
我正在尝试从REST Web服务的url请求中获取请求参数@路径能够映射方法。但是QueryParam无法从查询参数中获取值 我的请求Url是 192.168.20.147:8080/NestRestApi/rest/hello/ScripInfo/MACLEAN1-11365/nse_cm/531335Java @QueryParam取消绑定以获取请求参数,java,rest,jax-rs,Java,Rest,Jax Rs,我正在尝试从REST Web服务的url请求中获取请求参数@路径能够映射方法。但是QueryParam无法从查询参数中获取值 我的请求Url是 192.168.20.147:8080/NestRestApi/rest/hello/ScripInfo/MACLEAN1-11365/nse_cm/531335 package Rest; import com.omnesys.nest.classes.CNestQuotes; import com.omnesys.nest.constants.N
package Rest;
import com.omnesys.nest.classes.CNestQuotes;
import com.omnesys.nest.constants.NESTerror;
import java.io.IOException;
import java.util.Vector;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author maclean
*/
@Path("/hello")
public class ScripInfo {
/**
*
* @param AccountId
* @param Exch
* @param Symbol
* @return
* @throws ServletException
* @throws IOException
*/
@GET
@Path("/ScripInfo/{AccountId}/{exch}/{sym}")
@Produces(MediaType.APPLICATION_ATOM_XML)
public String getScripInfo(@QueryParam("AccountId") String AccountId,@QueryParam("exch") String Exch, @QueryParam("sym") String Symbol) throws ServletException, IOException
{
CNestQuotes oNestQuote = new CNestQuotes();
oNestQuote.sExchSeg=Exch;
oNestQuote.sLoginId=AccountId;
oNestQuote.sSymbol=Symbol;
HttpServletRequest request = null;
HttpServletResponse response = null;
request.setAttribute("QuoteStruct", oNestQuote);
RequestDispatcher dispatch =request.getServletContext().getRequestDispatcher("/NESTGetOMScripInfo") ;
dispatch.include(request, response);
Vector oResult = (Vector) request.getAttribute("NESToutObject");
if (oResult == null || oResult.size() == 0 || oResult.contains(NESTerror.BAD_INPUT) || oResult.contains(NESTerror.NO_DATA) || oResult.contains(NESTerror.MSG_FAILURE)) {
} else {
oNestQuote = (CNestQuotes) oResult.firstElement();
}
return null;
}
}
AccountId
、exch
和sym
不是查询参数,而是路径参数,因此使用AccountId
而不是@QueryParam
来代替@PathParam
,exch
和sym
不是查询参数,而是路径参数,因此使用@QueryParam
而不是@PathParam
而不是对AccountId使用QueryParam,exch和sym应该使用@PathParam
在JAX-RS中,可以使用@PathParem将@Path expression中定义的URI参数值注入Java方法
/用户/查询?名称=Nasruddin
在上面的URI模式中,查询参数是“nanme=Nasruddin”,您可以使用@QueryParam(“url”)获取url值,而不是使用QueryParam作为AccountId、exch和sym,您应该使用@PathParam 在JAX-RS中,可以使用@PathParem将@Path expression中定义的URI参数值注入Java方法 /用户/查询?名称=Nasruddin 在上面的URI模式中,查询参数是“nanme=Nasruddin”,您可以使用@QueryParam(“url”)获取url值