如何从JAX-WS Web服务中访问ServletContext? [英] How can I access the ServletContext from within a JAX-WS web service?

查看:114
本文介绍了如何从JAX-WS Web服务中访问ServletContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过将其存储为servlet上下文属性来共享我的servlet和我的webservice(JAX-WS)之间的对象。但是如何从Web服务中检索servlet上下文?

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 service?

推荐答案

JAX-WS通过以下方式提供servlet上下文消息上下文,可以使用Web服务上下文检索。插入以下成员将导致JAX-WS将Web服务上下文的引用注入Web服务:

The servlet context is made available by JAX-WS via the message context, which can be retrieved using the web service context. Inserting the following member will cause JAX-WS to inject a reference to the web service context into your web service:

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;

...

@Resource
private WebServiceContext context;

然后,您可以使用以下命令访问servlet上下文:

Then, you can access the servlet context using:

ServletContext servletContext =
    (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);

这篇关于如何从JAX-WS Web服务中访问ServletContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆