Solve the form post get to springMVC background confusion problem

  • 2020-12-18 01:50:07
  • OfStack

1. The foreground form is directly post or get, while the background form is received as request.getParameterMap () or request.getParameter ()

Note: Foreground, springmvc filters, and jsp, compiler encodings are all es11EN-8 examples

With request. getParameterMap (), for example

Note: Here is a method to get parameters from HttpServletRequest, while request is similar to


@RequestMapping("/tradePortal/ReceiveCommands") 
public ModelAndView receiveCommands(HttpServletRequest request, HttpServletResponse response){} 

In this method


public static Map<String,String> getParamters(HttpServletRequest request){
    logger.info(" Start getting the request parameters ");
    Map<?,?> paramterMap = request.getParameterMap();
    Map<String ,String> paraMap = new ConcurrentHashMap<String, String>();
    for (Map.Entry entry :
        paramterMap.entrySet()) {
      if (Array.getLength(entry.getValue())<1||StringUtil.isEmpty(((String)(Array.get(entry.getValue(),0))))){
        paraMap.put((String)entry.getKey(),null);
      }else {
        if (request.getMethod().equalsIgnoreCase("get")){
          try {
            paraMap.put((String)entry.getKey(),new String(((String)(Array.get(entry.getValue(),0))).getBytes("ISO-8859-1"),"utf-8"));
          } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
          }
        }else {
          paraMap.put((String)entry.getKey(),(String)(Array.get(entry.getValue(),0)));
        }
      }
    }
    logger.info(" The parameters are obtained. Parameters as follows: "+ JSON.toJSONString(paraMap));
    return paraMap;
  }

Related articles: