嗨我想从休息服务中的http会话对象访问anf的数据我已经google了很多,发现javax.ws.rs.core.Context的@context给出了HttpServlet对象但是因为它是interfaec我总是得到它空值。我的代码如下
@Context
private HttpServletRequest request;
private HttpSession session = request.getSession();
@Path(value = "/listAllQuestion")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response listAllQuestion(){
int pgNo = 1;
int pgSize = 5;
IPResponse response = new IPResponse();
try {
if (session.getAttribute(IpConstants.TOPIC) != null
&& session.getAttribute(IpConstants.LEVEL) != null) {
session.removeAttribute(IpConstants.TOPIC);
session.removeAttribute(IpConstants.LEVEL);
}
session.setAttribute(IpConstants.PAGENO, pgNo);
session.setAttribute(IpConstants.PAGESIZE, pgSize);
quesList = questionService.listAllQuestion(pgNo, pgSize);
答案 0 :(得分:0)
请试试这个:
将您的request.getSession()向下移动到listAllQuestion()方法中,如下所示:
public Response listAllQuestion(){
HttpSession session = request.getSession():
我不相信您的请求对象将填充在实际请求处理程序的上下文之外。