Preface : For example, there is a scenario, when the user is not logged in, click on the project, the investment project will need to prompt the user to sign in, and then pop up the login page, when the user login is completed, you can manipulate the corresponding page. In this case, permission interception is required, so using interceptor is invaluable.
Principle Introduction
When the user clicks on an action button, initiates a request to the server, the server authenticates the information, then transmits back to the front-end information, and the front-end receives the message, and the callback function is manipulated.
Service side
PackageCom.hc.jf.interceptor;ImportCom.jfinal.aop.Interceptor;ImportCom.jfinal.aop.Invocation;ImportCom.jfinal.core.Controller; Public class dealsinterceptor implements Interceptor { @Override Public void Intercept(Invocation inv) {Controller Controller = Inv.getcontroller (); String username = controller.getsessionattr ("username");//If the user is not logged in, then jump to the login page if(Username = =NULL|| Username.equals ("") {controller.setattr ("StatusCode", $); Controller.setattr ("Message","User not logged in");//user is not logged in, the Login confirmation box pops upController.setattr ("Show_pop_login","Show_pop_login"); Controller.renderjson (); }Else{Inv.invoke (); } }}
How to use interceptors, refer to Jfinal's official help document.
Front
<a href="${ctx}/project" class="btn_publish" target="ajaxTodo" callback="ajaxDone"></a>
Attention:
1. Target of the published project
2. Callback
When the server detects that there is no login, it passes a show_pop_login parameter back, which is used to provide the callback function Ajaxdone method to implement the popup login window
function ajaxdone (JSON) { yunm.ajaxdone (JSON); if (Json[yunm.keys.statuscode] = = YUNM.statusCode.ok | | json[yunm.keys.statuscode] = = YUNM.statusCode.info) {//if a local refresh event is returned, perform a partial refresh if (json.loadp Age) {//if you specify a post-invert page, reverse the $ ( "#" + Json.elementid). Load (Common.loadpath + json.loadpage + common.viewtype); } //overall refresh if (Json.locationurl) { Location.href = Json.locationurl; } if (json.show_pop_login) {show_pop_login (); } }}
This enables the interception of jumps between pages.
Conclusion : This article only introduces the relevant methods, you need to refer to the series of articles for research.
Copyright notice: This site blog is qing_gee original article, if you need to quote, reprint, only need to indicate the source and the original link.
Jfinal Interceptor Interceptor Analysis