AD

DWR push technology in the development of necessary attention to the problem ScriptSession

1 About ScriptSession
ScriptSession not created simultaneously with the HttpSession
When we visit a page, if this is the first time to visit, it will create a new HttpSession, after the time of the visit will be to maintain the current Session, even if the refresh are also able to maintain the current HttpSession.
However, ScriptSession different first visit, will create a ScriptSession, but if you refresh, it will create a new ScriptSession.

2 how to get ScriptSession
At DWR, we can WebContextFactory.get () to obtain a WebContext object, and then through WebContext the getScriptSession () to obtain the object ScriptSession.
However, attention should be paid, at the Servlet our custom, we can also WebContextFactory.get () to obtain a WebContext, but this method can not be achieved ScriptSession object. Since this object is not WebContext through DWR the context of the environment, and therefore, they did not have any object to create ScriptSession.
Assumptions in this way can also be ScriptSession, then we achieve "push" it can not be confined to the DWR in the context of the environment, then its flexibility will be a lot of the big.

So, this is what we should not push the implementation of the Servlet reasons.

Refresh on about 3 to create a new problem ScriptSession
We need to push at the page, if you refresh the following, then submit a Http's request, at this time, if it is first, then create an HttpSession object, simultaneously, the request by the DwrServlet to deal with, we will create a ScriptSession. this ScriptSession and you request the URI of the request in a bind by ScriptSessionManager maintained Map inside (there is actually a URI corresponding Set, placed inside Set at URI are binding for all ScriptSession).
When you refresh, the same as a HttpSession, but it will create a new ScriptSession, then bind to the corresponding URI on.

4 to all pages visitors Push
When we want to push all of the pages a visitor, we only need to obtain all of the pages a visitor, you can "push" the.
How to obtain all of the pages the visitor? Can
/ / Collection pages = webContext.getScriptSessionsByPage ( "/ SynMap / map / map.jsp");
To obtain / SynMap / map / map.jsp all visit ScriptSession
How to push,
Util util = new Util (pages);
util.addFunctionCall ( "syningMap", new Double (x), new Double (y), new Integer (zoom));
Through this method, you can call the client achieve the javascript function, implementation of the client's operation.

5 Push in the above questions arise
The above methods can achieve all of the visitors to push. But the problem is that the client, if the user refreshes one or more times, then, Collection which may save a lot of useless ScriptSession, so not only will affect the performance problem, but more importantly is that you probably would not want to to function.

For instance, you want to obtain the current representation of a valid user, then you need to know those who are ScriptSession effective.

6 how to manage effective ScriptSession

Because of the above questions, we need to manage ScriptSession. In fact, the effective HttpSession, is that the HttpSession and the current match ScriptSession.
Therefore, we can maintain a Map, in the Map inside, our key is the definition of HttpSession of Id, the value is ScriptSession object.
At each time the page loading time, all this Registration go ScriptSession, then put the new ScriptSession above bound to the HttpSession.
/ / Session and scriptSession map
Map sm = g.getSessions ();
/ / Hs is HttpSession
/ / Ss is ScriptSession object
sm.put (hs.getId (), ss);

7 How to achieve an effective push
Map obtained through above all effective ScriptSession Collection
Collection pages = g.getSessions (). Values ();
Then pushed send on it.

Eight of the questions above, new solutions
The above technical problems and solutions are at DWR2.0 environment encountered.
Yesterday, look, is about to officially release the document DWR3.0 inside of AJAX Reverse technology has added many features.
Add a new one of like HttpSessionListener things, called ScriptSessionListener
So, I think, you can achieve the above through the Listener function, that is to say, in listening to a ScriptSession created, we directly judgment and put this on ScriptSession bound to the HttpSession, it. The same with the above map to manage it.
This is my train of thought, I have not in practice, if you need to do so, can go try.
DWR to develop a new version of push technology implementation will be more convenient, look forward to it! !

With the original address: **blog.csdn**/zhijie435/archive/2008/10/24/3135712.aspx
标签: implementation, map, bind, assumptions, dwr, flexibility, httpsession object, necessary attention, push technology, uri
分类: AJAX
时间: 2009-04-29

相关文章

  1. DWR push technology in the development issues require attention ScriptSession

    1 on ScriptSession At the same time ScriptSession not create HttpSession When we visit a page, if this is the ...
  2. DWR push technology in the development of problems that need attention ScriptSession

    1 About ScriptSession ScriptSession At the same time will not create HttpSession When we visited a page when , ...
  3. Beginners dwr push technology (to summarize)

    Here is what I've seen in two small instances of online The first one: DWR2.0.x push technology to send a mess ...
  4. DWR push technology issues ScriptSession

    1 About ScriptSession ScriptSession the same time will not create HttpSession when we visit a page, if a first ...
  5. Dwr push technology learning

    Examples: web.xml file configuration: <servlet> <servlet-name> dwr-invoker </ servlet-name> ...
  6. DWR Server Push (server push technology) to achieve real-time chat

    Transfer: http://rickycm.javaeye.com/blog/419380 Message when you have QQ, QQ will rock the small icon, and we ...
  7. Push technology to achieve the chat room

    Push-based chat rooms in China are now more common . The greatest feature of this chat room is to not use the ...
  8. DWR2.0.x of push technology

    DWR2.0.x of push technology, also known as DWR Reverse Ajax (Reverse Ajax) primarily in the BS framework, from ...
  9. Comet, the next generation of reverse AJAX (or server push technology - Server-side push)

    Understanding of Comet You may have heard of Comet, because it has recently received some attention. Comet is ...
  10. Comet: HTTP long connection based on a "server push" technology

    http://www.ibm.com/developerworks/cn/web/wa-lo-comet/ Comet: HTTP long connection based on a "server push ...
  11. [Thesis] Server Push Technology Summary 1

    Server Push Technology 1 Background "server push technology" (Server Pushing) is the latest most pop ...
  12. Comet: HTTP-based long connection "server push" technology

    http://www.ibm.com/developerworks/cn/web/wa-lo-comet/ Comet: HTTP-based long connection "server push" ...
  13. Principles of Direct Push Technology

    Microsoft Exchange Server to the mobile device has had the ability to send messages, but the SMS-based synchro ...
  14. Printing system network technology evolution and development (under)

    Keywords: network printing system technology, history and development of cultural / Shaoxing County Textile Te ...
  15. Printing system network technology evolution and development (A)

    Keywords: network printing system technology, history and development of Chenshun Lin Chu Boliang Shaoxing Tex ...
  16. Server Push Technology

    Two days of server push technology, first click on the record, and then test the re-write something.
  17. Comet: a long connection based on HTTP "server push" technology

    Comet: The long connections based on http " Server push technology http://www.ibm.com/developerworks/cn/w ...
  18. HTTP-based push technology long connection: COMET

    1. The traditional model of Web system to a client request, the server response manner. This approach does not ...
  19. infoq technology Salon-Web App Development and Application and technology trends of 2011 Prospects

    infoq technology Salon-Web App Development and Application and technology trends of 2011 Prospects 2011-1-15 T ...