Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Struts2 interceptor simulation     - Install Java on RHEL6 (Linux)

- Solaris 10 installation configuration mrtg monitoring system (Linux)

- File permissions under Linux (Linux)

- Vim highlight lookup operation (Linux)

- Mybatis + binding Struts2: achieving user to insert and find (Programming)

- Bash command substitution (Programming)

- CentOS How to mount the hard drive (Linux)

- After Ubuntu Password Forgot your way back (Linux)

- File upload via AngularJS and ASP.NET MVC5 (Programming)

- Yii2 Advanced Version Copy New Project Problem Solved (Programming)

- Use ldap implement Windows Remote Desktop Ubuntu Linux (Linux)

- using the ssh command to check the socket / Network Connections (Linux)

- Java, boolean operators & =, | = ^ = use (Programming)

- Automate deployment of Docker-based Rails applications (Server)

- Use libpq under Ubuntu 14.04 (Linux)

- The Gitlab migrated to Docker container (Server)

- Linux character device - user mode and kernel mode data transfer data (Linux)

- Tor Browser: under Linux for anonymous Web browsing ultimate browser (Linux)

- LaTeX Getting Started Tutorial (Linux)

- Linux systems dmesg command processing failures and system information collected seven usage (Linux)

 
         
  Struts2 interceptor simulation
     
  Add Date : 2018-11-21      
         
         
         
  Preface:

Struts2 has been in contact for some time, Student core content by intercepting docking Action, to achieve control jumps View layer. In this paper, according to their own understanding of the Struts2 simulated a Java instance, to facilitate understanding!

Schematic diagram

Through simple diagram above, we can see Struts2 will ServletAPI business process separation allows developers to when a user sends a request to the client better for business process layer by intercepting mechanism, improve development efficiency. Here we have a few Java classes analog Struts2 interceptor implementation.

Interception principle

Code design:

1ActionInvocation

package com.simulink;

import java.util.ArrayList;
import java.util.List;

public class AntionInvocation {

    Action a = new Action ();
    int index = -1;
    List < Interceptor> interceptors = new ArrayList < Interceptor> ();

    public AntionInvocation () {
        interceptors.add (new FirstInterceptor ());
        interceptors.add (new SecondInterceptor ());
    }

    public void invoke () {
        index ++;
        // System.out.println ( "index:" + index);
        if (index> = this.interceptors.size ()) {
            a.execute ();
        } Else {
            this.interceptors.get (index) .intercept (this);
        }
    }

}

FirstInterceptor class

package com.simulink;

public class FirstInterceptor implements Interceptor {

    @Override
    public void intercept (AntionInvocation invocation) {
        System.out.println (-1);
        invocation.invoke ();
        System.out.println (1);
    }

}

SecondInterceptor class

package com.simulink;

public class SecondInterceptor implements Interceptor {

    @Override
    public void intercept (AntionInvocation invocation) {
        System.out.println (-2);
        invocation.invoke ();
        System.out.println (2);
    }

}

Class Action

package com.simulink;

public class Action {
    public void execute () {
        System.out.println ( "execute!");
    }
}

5 test class Main

package com.simulink;

public class Main {

/ **
* @param Args
* /
public static void main (String [] args) {
new AntionInvocation () invoke ().;
}

}

Output:

-1
-2
execute!
2
1
Postscript: contact WebWork friends should find struts2 with its very similar, in fact, Struts2 is Struts1 and WebWork combination. Its main technology comes from WebWork!
     
         
         
         
  More:      
 
- Hadoop1.2.1 plug compilation (Server)
- Oracle data files deleted recover after physical (Database)
- The OpenGL ES GLFW window structures (Programming)
- MySQL IO SSD attempt at optimization (Database)
- Storm how to ensure that at least once semantics (Programming)
- Spring + Log4j + ActiveMQ remote logging - Analysis of combat (Server)
- Sublime Text 3 using summary (Linux)
- lack of SWAP space during installation of Oracle (Database)
- How to install new fonts on Ubuntu 14.04 and 14.10 (Linux)
- Ubuntu 14.04 set auto sleep time (Linux)
- How to upgrade to Ubuntu 14.04 Ubuntu 14.10 (Linux)
- How to modify the Sublime in Tab four spaces (Linux)
- Linux rename command usage in learning to modify the file name (Linux)
- OpenGL Superb Learning Notes - Fragment Shader (Programming)
- Unity Greeter Badges: the lost session icon back to the login screen Ubuntu (Linux)
- Mounting Windows shared directory system under the Linux (Linux)
- To setup the Swift language learning environment under linux (Linux)
- Linux disk management practices (Linux)
- Linux Network Programming - libnet Guide (Programming)
- Commentary Apache + Tomcat + JK implement Tomcat clustering and load (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.