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
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());