How to get the ServletContext in Rest web service

后端 未结 2 1438
春和景丽
春和景丽 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:30

    Use @Context, here is Jersey documentation

    @Context
    private ServletContext context; 
    

    UPDATED - you can also inject directly into methods if desired

    public String uploadNotices(@Context ServletContext context, ...)
    

提交回复
热议问题