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 ~~~~~;