參考:springmvc 中controller與jsp傳值spring
springMVC:將controller中數據傳遞到jsp頁面mvc
jsp中,死活拿不到controller中的變量。app
花了半天,網上列出各類緣由。最後發現,是本身對springmvc中controller和jsp的傳值不理解致使jsp
controller的方法中須要返回Model的,這點是springmvc和struct的不一樣spa
第二種方法沒法返回,後續再探究爲啥.net
//列表 @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"; }