request的getAttribute()和getParameter()的区别

it2024-02-01  81

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()

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

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