I. Overview 1. First Knowledge InterceptorInterceptor interceptors are similar to the previously learned filters, which are code that can be executed before and after the action, and are the techniques we often use for web development. For example: Permission control, log, and so on. We can also connect multiple interceptor together to form the interceptor stack. Struts
Learn notes for the action before the interceptor or after the interceptor. from
After the teacher's test ... Add breakpoints to each interceptor ...Know:
The Action is executed at the time of the visit.
And the action is created before the params interceptor is executed.
So the conclusion is:
Action must precede the
for each request, the variables of the servlet life cycle such as request,session are encapsulated into a map, supplied for each action, and thread-safe, so in principle, is more memory-intensive.4, The interceptor implementation mechanism, STRUTS2 has its own interceptor mechanism, SPRINGMVC with the independent AOP way, so that
getUploadContentType () {return uploadContentType;} public void setUploadContentType (String uploadContentType) {this. uploadContentType = uploadContentType;} public String getUploadFileName () {return uploadFileName;} public void setUploadFileName (String uploadFileName) {this. uploadFileName = uploadFileName;} public String getAllowTypes () {return allowTypes;} public void setAllowTypes (String allowTypes) {this. allowTypes = allowTypes ;}}
If the form contains a file field whose name attribu
() {return uploadContentType;} public void setUploadContentType (String uploadContentType) {this. uploadContentType = uploadContentType;} public String getUploadFileName () {return uploadFileName;} public void setUploadFileName (String uploadFileName) {this. uploadFileName = uploadFileName;} public String getAllowTypes () {return allowTypes;} public void setAllowTypes (String allowTypes) {this. allowTypes = allowTypes ;}}
If the form contains a file field whose name attribute is xxx, the corres
interceptor comes from the idea of Spring AOP (for Aspect-Oriented Programming ).The interceptor adopts the responsibility chain mode.* In the responsibility chain mode, many objects are connected by each object's reference to its next home to form a chain.* Each node of the responsible chain can continue to call the next node or stop the process from being executed.In
The Interceptor is triggered when ajax initiates an action.
A problem occurred during project creation. When ajax initiates an action and triggers the interceptor, the returned value will not initiate a jump if it does not receive the same result, the pos form t can be used for submission.
After a long struggle, I have found a method that is not very scientific. I hope that someone with good intentions wil
Struts2 type conversion (1), struts2 type conversion1. type conversion Overview 1. From an HTML form to an Action object, type conversion is from string to non-string. Because HTTP does not have the concept of "type", each form input can only be a string or a string array. Therefore, on the server side, you must convert String to a specific data type. (For details, refer to section 6.1.1 in "OGNL, Data Tran
to use. public class IoCForStruts2 implements Servletrequestaware {
private HttpServletRequest request;
public void Setservletrequest (HttpServletRequest request) {
This.request = Request;
}
Public String Execute () throws Exception {
You can start working with the Request object
return action.success;
}
It appears that these properties are class-level and are not thread-safe and can cause problems. In fact, there is no problem with Struts2, because
, other pages can not be accessed, once the access immediately jump back to login.jsp, such as:Second, the production processThe process of login here is saved, the main explanation of how the filter is configured, has been done in many places, such as "Servlet" according to the concept of MVC design user login, user registration, Change password system (click to open the link), "Struts2" to create a simple, Basic
that implements the command mode (This process includes calling the Anction build itself before calling multiple interceptor build before () at the same time, ActionInvocation is set up to call the target Action in proxy mode. However, before the call, the ActionInvocation component loads all the Interceptor components (Interceptor) related to the target Action
From: The path to growth http://xugw.blog.sohu.com/124311370.html
Two steps for Interceptor 1. Write your own interceptor public class privilegecheckinterceptor extends
Abstractinterceptor {// Implement the interceptor Interface
Public String intercept (actioninvocation Invocation) throws exception {
System. Out. println ("privilegecheckinterceptor "
problem of hard coding.
Internal execution process of the 2,STRUTS2 frameworkIt says the execution of a file in MVC, and that's just a small part of it, now look at the implementation mechanism of the entire STRUTS2 framework, the following figure comes from the official website, and then adds its own changes.
As the above figure shows, the entire framework of the operation and tightly around the core fil
Configure the Web.xml to configure the STRUTS2 filter, for example:
Org.apache.struts2.dispatcher.FilterDispatcher
Struts.xml Main configuration file:
In Web applications we use deployment descriptors to initialize resources such as servlet, filter, listener, and so on, and this deployment descriptor is the well-known web.xml. Similarly, the framework uses a configuration file to initialize its own resources, which mainly incl
using interceptors
In web development we often encounter paging operations, a project may have more than one use to paging, then if the Java background using MyBatis as a persistence layer, we can use the MyBatis interceptor function to complete the entire project in multiple paging operations, reduce the code redundancy.
Interceptor Code
Intercept the Prepare method @Intercepts The parameter type is conne
actions in the module must share the same lifecycle.• Struts2 supports creating different lifecycles for each action through interceptor stacks. The stack can be used with different actions as needed.Struts. Action. ExtensionThe URL extension to use to determine if the request is meant for a struts actionUse the URL extension to determine whether the request is used as a struts action, that is, to set the
configuration entry in the Struts-default.xml file:
We seldom use bean elements in real-world development, because we generally do not extend or replace the core components of STRUT2.configuration of Constants (Constant)With constant configuration, you can change the behavior of the STRUTS2 framework and plug-ins to meet the needs of different Web applications.Constant configuration in Struts.xml:
Constant configuration in Struts.propertiesStruts
Struts2 core technology introduction, struts2 Core Technology
Struts2Core Technologies
To use the Struts2 framework, pay attention to the following three elements: configuration file, ing file, and Action:
Global attribute file struts. properties: stores some parameter variables run by the system. The entire system has only one attribute file;
Struts ing file str
consolidates struts, injects properties for struts action, implements Web application timed tasks, online demographics, etc.Interceptor differs from filter:(1) Not configured in Web. XML, but complete configuration in Struts.xml, with action(2) Which interceptor can be specified by the action to work before receivingThe difference and connection between filters and interceptors in Struts2:(1), interceptors
Interceptors Intercprot and filter filters actually act likeWhen I first approached Java using STRUTS2, it was all filterLater, SPRINGMVC, use Interceptor.Not too concerned about the difference, anyway, is the role of inspection,READ carefully the difference between the filter and the Interceptor (Interceptor) and understand a lotThe most important thing to remem
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.