Get HttpServletRequest in Jax Rs / Appfuse application?

前端 未结 2 1748
情歌与酒
情歌与酒 2020-12-06 04:29

I created a basic application shell with AppFuse, and followed the AppFuse tutorial to create a a simple RESTful service with Jax-RS. That works just fine. A call to

相关标签:
2条回答
  • 2020-12-06 04:50

    Adding it to the method signature worked. I imagine it's because the request and response objects don't yet exist when the class is instantiated, but does when called by the brower.

    @Path("/")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    List<Person> read( @Context HttpServletRequest httpServletRequest, @Context HttpServletResponse httpServletResponse) { }
    
    0 讨论(0)
  • 2020-12-06 05:01

    Try injecting the HttpServletRequest and HttpServletContext directly:

    @Context private HttpServletRequest servletRequest;
    @Context private HttpServletContext servletContext;
    
    0 讨论(0)
提交回复
热议问题