从Web服务访问FacesContext

编程入门 行业动态 更新时间:2024-10-25 13:16:24
本文介绍了从Web服务访问FacesContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个Web服务,该服务将由我编写的客户端调用.在Web服务中,我需要使用应用程序范围的对象,这可以减轻系统上应用程序的负担.我已经实现了我的应用程序范围内的对象,如此问题.

I'm developing a Web Service which will be called by clients which are written by me. In the web service I need to use application-wide objects which eases the load of application on the system. I have implemented my application-wide objects as shown in this question.

我可以在jsf页面中毫无问题地使用我的对象,如下所示.

I can use my object in a jsf page with no problem as follows.

MyObject mo = (MyObject) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("MyObjectsName");

但是在Web服务请求中使用它时,FacesContext.getCurrentInstance()返回null.有什么方法可以在Web服务中使用FacesContext.

But when it comes to use it in a Web Service Request FacesContext.getCurrentInstance() returns null. Is there any way to use the FacesContext in a web service.

推荐答案

它为null,因为Web服务不是通过Faces Servlet来的.这就是应有的方式,因为Web服务与JSF无关.

It is null, because web services don't come through the Faces Servlet. And this is the way it should be, because web services have nothing to do with JSF.

如果您使用的是jax-ws实现,则可以使用:

In case you are using a jax-ws implementation, you can use:

@Resource WebServiceContext context;

这将注入WebServiceContext,通过它您可以:

This will inject the WebServiceContext, by which you can:

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

有了ServletContext,您就可以访问应用程序作用域的对象.

And having the ServletContext, you can access your application-scope objects.

更多推荐

从Web服务访问FacesContext

本文发布于:2023-10-07 17:37:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470050.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Web   FacesContext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!