CheckboxInterceptor: the interceptor is at the position of defaultStack 11th. Check that the interceptor name is used to process the checkbox. To understand the role of this interceptor, you must know that when a form contains a checkbox, assume that the name attribute value of this checkbox is married, when we select this checkbox, the request parameter command contains a married = true parameter, and when we do not select this checkbox, there is no such married parameter in the request parameter, this is equivalent to the fact that the checkbox does not exist at the root of the form. In most cases, the result is that when the checkbox is not selected, the married parameter is included in the request parameter set, but its value is "false ". The problem arises, and the interceptor can be used to solve this problem. The following is the source code of the intercept method of the Interceptor: [java] public String intercept (ActionInvocation ai) throws Exception {Map parameters = ai. getInvocationContext (). getParameters (); // obtain the request parameter Map <String, String []> newParams = new HashMap <String, String []> (); // create a new parameter Map Set <Map. entry> entries = parameters. entrySet (); for (Iterator <Map. entry> iterator = entries. iterator (); iterator. hasNext ();) {// iterative request parameter Map. entry entry = I Terator. next (); String key = (String) entry. getKey (); // obtain the key of the Request Parameter of the current iteration, that is, the name attribute value of the form field if (key. startsWith ("_ checkbox _") {// determines whether the key uses the _ checkbox _ switch String name = key. substring ("_ checkbox _". length (); // obtain the string following the current key _ checkbox _ // obtain the value of the current entry Object values = entry. getValue (); iterator. remove (); // remove the current entry if (values! = Null & values instanceof String [] & (String []) values ). length> 1) {// if you enter the if statement, it indicates that the same checkbox is set twice, and the next entry LOG is directly entered. debug ("Bypassing automatic checkbox detection due to multiple checkboxes of the same name: #1", name); continue ;}// determine whether the checkbox named name variable value is selected, if (! Parameters. containsKey (name) {// if it is not selected, add a newParams string array with the length of the key as name variable value to the new parameter Map. put (name, new String [] {uncheckedValue}) ;}}// Add the new parameter Map to the request parameter Map parameters. putAll (newParams); // call the next interceptor return ai. invoke ();} to better understand the functions of the interceptor, the following table lists [html] <form action = "xtayfjpk. do "method =" post "> <input type =" checkbox "name =" married "value =" 3 "/> married <br/> <input type =" hidden "name = "_ checkbox_married"/> <br/> <Input type = "submit" value = "submit"/> </form> after entering the interceptor, determine whether the name attribute value of the current iteration starts with _ checkbox, if the _ checkbox _ switch is not used, no operation is performed. If it starts with _ checkbox _, the Section after _ checkbox _ is truncated. Here, married is obtained, obtain the value of the _ checkbox_married parameter, remove the parameter from the request parameter Map (because this parameter is only a tag), and then obtain the value of _ checkbox_married, the normal condition should be null, but if there is a value, it indicates that the checkbox with the same meaning is set twice, so that a debug information will be printed and the following operations will not be executed. If the normal condition is null, check whether the married checkbox is selected. If the married parameter is selected, it will be in the request Parameter Map. If it is not selected, it will not, but it will pass newParams. put (name, new String [] {uncheckedValue}); this code assigned married a 1-character String array with the value of uncheckedValue, which can be set, the default value is "false". add all the data in newParams to the request parameter Map to complete the logic and then call the next interceptor. I wonder if you have found that the retrieved Request Parameter Value Returns a String [] instead of a String. Take the checkbox as an example. If you use multiple checkboxes to select a hobby, in this way, there may be multiple hobbies, so we need to use a String [] to receive them. In order to receive the same parameter, the returned value is also a String [], but the array length is 1. Since a parameter name can receive multiple parameter values, why does the following Code no longer run when _ checkbox_married has a value in the preceding example? This is because the _ checkbox_married parameter is only used to identify whether the interceptor needs to process married checkbox when it is not selected, and normally there should be no value. To make the interceptor valid, you must add a field named "_ checkbox _" + name attribute value of the checkbox to be processed in the form. Here I will talk about some details about the method for obtaining the parameter value of the request object: when the request is called. getParameter (key) returns a string that calls request. getParameterMap. get (key) returns a string array. At first, it was a bit confusing and thought that the returned value should be the same, but here there are different results (the key is the same ), later, I found out the source code of Tomcat. Request. getParameter (key), actually calling org. apache. tomcat. util. http. the getParameter (String name) method in the Parameters class: [java] public String getParameter (String name) {handleQueryParameters (); ArrayList values = (ArrayList) this. paramHashValues. get (name); if (values! = Null) {if (values. size () = 0) return ""; return (String) values. get (0); // returns the element with index 0} return null;} request. getParameterMap. get (key), actually calling org. apache. tomcat. util. http. the getParameterMap method in the Parameters class: [java] public Map getParameterMap () {if (parameterMap. isLocked () return parameterMap; Enumeration enumeration = getParameterNames (); while (enumeration. hasMoreElements () {String name = enumeration. nextElement (). toString (); String [] values = getParameterValues (name); // obtain the value array parameterMap. put (name, values); // put in parameterMap} parameterMap. setLocked (true); return parameterMap;} public String [] getParameterValues (String name) {// this method obtains the value array handleQueryParameters (); ArrayList values = (ArrayList) this. paramHashValues. get (name); if (values = null) return null; return (String []) values. toArray (new String [values. size ()]); // converts values ArrayList to String [] and returns}