Dwr3.0 Pure Annotation (pure Java code Configuration) configuration and application analysis of the three-port reverse call front-end _java

Source: Internet
Author: User

In the first two articles we have introduced the DWR 0 configuration culture and front-end call back-end method, presumably we should have mastered the master, down we mainly discuss how to reverse the back end of the call to the front of the JS method;

As mentioned in the top two mentioned in the DWR registered two service components, one is remote, the other is the page to use the controller, this remote is loaded in the page will be called, This makes the session and page Scriptsession set up a binding relationship, convenient for us to use its Scriptsessionid for page orientation push;

Here's how to create a session and page Scriptsession (which will be invoked when the page is just loaded):

Scriptsession scriptsession = Webcontextfactory.get (). Getscriptsession (); 
String jsessionid = Scriptsession.gethttpsessionid (); 
String Dwrsessionid = Scriptsession.getid (); 
Logger.info (String.Format ("Set jsessionid = [%s],dwrsession = [%s] Push enabled", Jsessionid,dwrsessionid)); 
Constantcacheservice.putcacheconstant (Constants.push_id+jsessionid, Dwrsessionid);
Here is the service method used to reverse call the front end:
@Service ("Dwrreverseajaxservice") public
class Dwrreverseajaxservice {
private static final Logger Logger = Loggerfactory.getlogger (dwrreverseajaxservice.class);
public void Directwebremotingwithsession (HttpSession session, Final String functionname) 
{assert.notnull , "[DWR Reverse Ajax] session can is not null!");
Final String Scriptsessionid = constantcacheservice.getcacheconstantvalue (constants.push_id + session.getid ());
Logger.info ("[DWR session ID] =" + Scriptsessionid + "[Script Function Name] =" + functionname); Browser.withsession (Scriptsessionid, New Runnable () {public
void run () {Scriptsessions.addfunctioncall ( FunctionName, "");}}
);}

This service is using the Scriptsessionid to reverse position push, and this scriptsessionid is the use of our previous page just loaded in on the set up to save to a global map to the inside;

Down as long as you want to call when the use of the registered service bean can be, passed in the parameters for httpsession and you want to call the front-end JS Funciton name, while noting that the current page exists this JS function, And generally is the main page of JS inside the method can be accessed, otherwise the front-end will prompt the method undefined error;

The above is about the simple application of DWR, is purely the first use, there is nothing wrong, please correct me out, thank you! Great God, please drift across the ~~~~~;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.