View Javadoc

1   package com.diasparsoftware.javax.servlet;
2   
3   import java.util.*;
4   
5   import javax.servlet.http.HttpServletRequest;
6   
7   import org.apache.commons.collections.*;
8   
9   public class ServletUtil {
10  
11      /***
12       * Provides a nicer string representation of a
13       * servlet request parameter map.
14       * 
15       * @param request  The request whose parameters you
16       * want to display
17       * @return   A nice string representation of the
18       * parameters to the specified request
19       */
20      public static String parameterMapToString(HttpServletRequest request) {
21          final Map parameters = new HashMap();
22  
23          Closure convertArrayToListClosure = new Closure() {
24              public void execute(Object eachMapEntryAsObject) {
25                  Map.Entry eachMapEntry =
26                      (Map.Entry) eachMapEntryAsObject;
27  
28                  String name = (String) eachMapEntry.getKey();
29                  String[] values = (String[]) eachMapEntry.getValue();
30  
31                  parameters.put(name, Arrays.asList(values));
32              }
33          };
34  
35          CollectionUtils.forAllDo(
36              request.getParameterMap().entrySet(),
37              convertArrayToListClosure);
38  
39          return parameters.toString();
40      }
41  
42  }