Struts2 Interceptor (0): getting started

Source: Internet
Author: User

Interceptor systemIs an important part of the struts2 framework, a large numberBuilt-in interceptorCompleted most of the operations on the framework. For exampleParamsThe Interceptor is responsible for parsing HTTP Request Parameters and setting Action attributes;ServletconfigThe interceptor directly transmits the httpservletrequest instance and httpservletresponse instance to the action;FileuploadThe Interceptor is responsible for parsing the file fields in the request parameters, and setting a file field to the three attributes of Action ...... these general operations are completed through the built-in interceptor of struts2.

Struts2 interceptor is a plug-in design: to use an interceptor, you only need to apply the Interceptor to the configuration file. If you do not need to use the interceptor, you only need to cancel applying the interceptor in the configuration file. Whether or not an interceptor is applied, the struts2 framework will not be affected.

Struts2 interceptor is managed by configuration files such as struts-default.xml and struts. xml. It is easy for developers to expand their interceptors so that they can expand the struts2 framework to the maximum extent.

Most of the functions of the struts2 framework are implemented through the interceptor.StrutsprepareandexecutefilterAfter a user request is intercepted, a large number of interceptor processes the user request and then calls the method of the Action instance developed by the user to process the request.

Struts2 has a large number of built-in interceptors, which are configured in the form of name-class PairsStruts-default.xmlIn the file, name is the name of the interceptor, and class is the implementation class of the interceptor.

<interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor"/><interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/><interceptor name="chain" class="com.opensymphony.xwork2.interceptor.ChainingInterceptor"/><interceptor name="conversionError" class="org.apache.struts2.interceptor.StrutsConversionErrorInterceptor"/><interceptor name="cookie" class="org.apache.struts2.interceptor.CookieInterceptor"/><interceptor name="clearSession" class="org.apache.struts2.interceptor.ClearSessionInterceptor" /><interceptor name="createSession" class="org.apache.struts2.interceptor.CreateSessionInterceptor" /><interceptor name="debugging" class="org.apache.struts2.interceptor.debugging.DebuggingInterceptor" /><interceptor name="externalRef" class="com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptor"/><interceptor name="execAndWait" class="org.apache.struts2.interceptor.ExecuteAndWaitInterceptor"/><interceptor name="exception" class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"/><interceptor name="fileUpload" class="org.apache.struts2.interceptor.FileUploadInterceptor"/><interceptor name="i18n" class="com.opensymphony.xwork2.interceptor.I18nInterceptor"/><interceptor name="logger" class="com.opensymphony.xwork2.interceptor.LoggingInterceptor"/><interceptor name="modelDriven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/><interceptor name="scopedModelDriven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"/><interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor"/><interceptor name="actionMappingParams" class="org.apache.struts2.interceptor.ActionMappingParametersInteceptor"/><interceptor name="prepare" class="com.opensymphony.xwork2.interceptor.PrepareInterceptor"/><interceptor name="staticParams" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"/><interceptor name="scope" class="org.apache.struts2.interceptor.ScopeInterceptor"/><interceptor name="servletConfig" class="org.apache.struts2.interceptor.ServletConfigInterceptor"/><interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor"/><interceptor name="timer" class="com.opensymphony.xwork2.interceptor.TimerInterceptor"/><interceptor name="token" class="org.apache.struts2.interceptor.TokenInterceptor"/><interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/><interceptor name="validation" class="org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor"/><interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"/><interceptor name="store" class="org.apache.struts2.interceptor.MessageStoreInterceptor" /><interceptor name="checkbox" class="org.apache.struts2.interceptor.CheckboxInterceptor" /><interceptor name="profiling" class="org.apache.struts2.interceptor.ProfilingActivationInterceptor" /><interceptor name="roles" class="org.apache.struts2.interceptor.RolesInterceptor" /><interceptor name="jsonValidation" class="org.apache.struts2.interceptor.validation.JSONValidationInterceptor" /><interceptor name="annotationWorkflow" class="com.opensymphony.xwork2.interceptor.annotations.AnnotationWorkflowInterceptor" /><interceptor name="multiselect" class="org.apache.struts2.interceptor.MultiselectInterceptor" />

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.