How to get the ServletContext in Rest web service

后端 未结 2 1433
春和景丽
春和景丽 2021-02-13 20:39

I am implementing rest web service using Jersey. I need to have object of ServletContext to save the file in the application directory. Please help me to get the context.

<
2条回答
  •  别那么骄傲
    2021-02-13 21:24

    use the annotation @context (Method level injection)

    public Response getContext(@Context HttpServletRequest req, @Context HttpServletResponse res)throws Exception
    {   
        System.out.println("Context Path is:"+req.getRequestURL().toString());
        result=req.getRequestURL().toString();
        return Response.status(200).entity(result).build();
    }
    

提交回复
热议问题