In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Flex Remote Object in the direct use of HttpSession method is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
We can use Remote Object as the Service Facade and use the persistent service provided by the application server to store state information.
The method of using HttpSession directly in Flex Remote Object
The background of the problem
Flex Remote Object can be POJO,JavaBean or EJB. In service-oriented architecture (Service Oriented Architecture), we can use Remote Object as Service Facade and use the persistent service provided by the application server to store state information.
Flex can provide remote object for stateful or stateless, as well as session servlet for mxml to get / store content in session. All this sounds *, but there is a problem that Flex Remote Object itself can't get any information about Running Context, that is, you can't get HttpSession, HttpRequest and ServletContext from your Remote Object. The so-called Flex Session servlet just gives MXML access to the content of session, not directly to Remote Object to get session.
Why does Remote Object need to get HttpRequest, HttpSession?
Why let remote object get Running Context when Flex provides stateful's remote object? The problem is that the stateful in Flex is based on the http session of the application server, and you can't control the process of AMFGateway building remote object. To make a simple analogy, we know that in the average application server, the session time limit is only 20 minutes, but in many systems there is the option of keeping the login for a few months.
Its specific implementation is to use cookie to store id and password hash, by controlling the survival time of cookie to achieve. On the server side, once the session expires, you can get id and password hash from cookie to log in again, so as to achieve the purpose of automatically authenticating users.
If your Flex Remote Object cannot get HttpServletRequest and HttpSession, you will not be able to achieve the above situation. In addition, for small applications, obtaining servlet context directly in Remote object and using it to store / obtain shared resources can greatly reduce the complexity of development.
Solution
It is not easy for Flex Remote Object to get HttpSession,HttpRequest and ServletContext. Here is one of my methods for your reference. I hope I can throw a brick to attract jade, so that everyone can come up with a better and more effective plan.
The basic idea of this approach is to make use of the ThreadLocal Object provided by JAVA. When the server receives a HTTP request, the entire processing of the request is run in the same thread.
The processing of each HTTP request runs in a separate thread. In Flex, all AMF Remote Object requests need to go through AMF Gateway Servlet, and the establishment and invocation of Remote Object is run in the thread of the HTTP request.
With this principle, we can create a Context Object, and whenever the request is created, we can put the request into the ThreadLocal of Context, and when the Remote Object is called by AMF Gateway Servlet, we can get the corresponding request by accessing the ThreadLocal of Context.
Intercepting requests sent to AMF Gateway can be achieved through Servlet Filter. Stop talking nonsense and look at the code!
1. Add the following to WEB-INF/web.xml
AMFSessionFilter com.netop.forum.servlets.AMFSessionFilter AMFSessionFilter AMFGatewayServlet
two。 How to use AMFContext in Flex Remote Object
Class YouRemoteService {public void serviceMethod () {AMFContext context = AMFContext.getCurrentContext (); HttpSession = context.getSession (); ServletContext = context.getServletContext (); HttpServletRequest request = context.getRequest (); HttpServletResponse response = context.getResponse (); context.setSessionAttribute ("attr", "value"); context.setContextAttribute ("attr", "value");} is it helpful for you to read the above? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.