Login Check blocker (Actioninvocation's understanding)

Source: Internet
Author: User

What is 1.actionInvocation?

Actioninvocation is the caller of the action. Actioninvocation is responsible for the dispatch of a series of elements, such as interceptor, action, and result, during action execution.

Understanding actioninvocation You need to have a thorough understanding of the action invocation process:

http://tech.ddvip.com/2009-01/1232090919106049.html

It's still very clear to say.

2.ActionInvocation what?

Interceptor can completely change the action behavior by actioninvocation: Do not let it execute, change the return value, or even fine-grained operation of the action method

View Actioninvocation's API, he has Getactionproxy (), Getresultcode (); Getactioncontext ();

actionproxy constructs the execution environment in action, Actionproxy provides the configuration, parameters, and so on when the action executes, and, of course, the entrance to the action call.


Public String intercept (actioninvocation invocation) throws Exception { 
Map session= Invocation.getinvocationcontext (). getsession ();
	    String  Actionname=invocation.getproxy (). Getactionname ();
	    String  Methodname=invocation.getproxy (). GetMethod ();
} You have this method when you write the filter, if you do not inherit extends Abstractinterceptor

Example:
Public String intercept (actioninvocation invocation) throws exception{
	Actioncontext  CTX = Invocation.getinvocationcontext ();
	If the requested action exists within the appropriate scope, return directly to the Intercept method and invoke the action to execute
	for (String action:whitelist) {
		if (Ctx.getname (). Equals (action)) {
			return Invocation.invoke ();
		}
	}
	If the requested action is not within the defined range, see if you are logged in and have permission to do this action
	HttpSession session = Servletactioncontext.getrequest (). GetSession ();
	if (Session.getattribute ("session_admin") = = null) {
		Session.setattribute ("Sessionerrormessage", "Please login to the system first.") ");
		return "LoginError";
	}
	If the requested action is not within the scope, but is already logged in, the action request is executed directly
	return Invocation.invoke ();
}

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.