Jfinal Interceptor Interceptor Analysis

Source: Internet
Author: User

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

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.