How can I access the ServletContext from within a JAX-WS web service?

后端 未结 2 648
遥遥无期
遥遥无期 2020-12-02 09:06

I want to share an object between my servlets and my webservice (JAX-WS) by storing it as a servlet context attribute. But how can I retrieve the servlet context from a web

2条回答
  •  抹茶落季
    2020-12-02 09:55

    If you use Maven add this dependency!!!

            
                javax.servlet
                servlet-api
                2.4
                provided
            
    

    So I solved for avoid conflict error for get ServletContext INFO :

    And in class method I use

    @WebService(endpointInterface = "choice.HelloWorld")
    public class HelloWorldImpl implements HelloWorld {
        @Resource
        private WebServiceContext context;
        public String sayHi(String text) {
            HttpServletRequest request =(HttpServletRequest) context.getMessageContext().get(MessageContext.SERVLET_REQUEST);
            System.out.println(request.getContextPath());
    

提交回复
热议问题