问题
We have a Spring REST environment which is producing json response. Below is the code which is used to send the json response
@GET
@Path("/userinfo.json/{userid}")
@Produces("application/json")
public List<UserinfoBean> getUserAllInformation(@PathParam("userid") String userid)
{
return openServicesAPI.getUserAllInformation(userid);
}
Can anyone let me know how I can set the request/response attribute and if at all possible create an HTTPsession here.
回答1:
Use @Context
this will give you the Contextual information
getUserAllInformation(@Context HttpServletRequest request,
@Context HttpServletResponse response,
@PathParam("userid") String userid){
//...
}
来源:https://stackoverflow.com/questions/14744442/setting-request-response-attributes-in-spring-rest-environment