參考:springmvc 中controller與jsp傳值
springMVC:將controller中數據傳遞到jsp頁面
jsp中,死活拿不到controller中的變量。
花了半天,網上列出各種原因。最后發現,是自己對springmvc中controller和jsp的傳值不理解導致
controller的方法中需要返回Model的,這點是springmvc和struct的不同
第二種方法無法返回,后續再探究為啥
//列表 @RequestMapping("/listAll") public String listAll(Map<String,Object> model){ List<Person> personList = ps.listAll(); model.put("personList", personList); System.out.println(" listall hello"); return "person/jPersonList"; } //列表 @RequestMapping("/listAllOther") public String listAllOther(Model model){ List<Person> personList1 = ps.listAll(); model.addAttribute(personList1); System.out.println(" listallother1 hello"); return "person/jPersonList"; }