request.getParameter()与request.getAttribute()区别

request.getAttribute():

  • 总体来说这个getAttribute() 是在页面中获取后台传递来的数据
    这个getAttribute() 配套的是setAttribute() , 但是他取值得范围不仅限于setAttribute()的值。通过Model类型的addAttribute() 以及通过ModelAndView的addObject()添加的数据。在页面中都可以通过request.getAttribute() 来获得。不过一般都是使用EL直接取值的方式替代该方法。
//一下三种方式都可以在页面中通过request.getAttribute() 获得
modelMap.addAttribute("object","object"); 
request.setAttribute("aaa", "aaaa");
ModelAndView mav = new ModelAndView();
mav.addObject("msg","hahahahahaha!");

request.getParameter()

该方法主要是后台获取前台页面出传递过来的数据

  1. get方式提交时,连接后边追加的参数。
  2. 表单中提交的参数。
  3. 注: getParameter()是获取不到前台页面中setAttribute()的值的。