springMVC中的Model是不能页面之间传递的?

springMVC中的Model是不能页面之间传递的?

问题描述:

我的请求被controller拦截,进入controller,然后controller跳转至show.jsp,
跳转之前我往show.jsp页的model里面增加了几个key,

然后我在show页去ajax另一个controller,这时候ajax调用的controller是无法获取
show.jsp页面的model的,这是为什么?request不是也可以在页面之间传递吗?

下方为代码:
第一次跳转页面的controller

 @RequestMapping("/show")
    public String showMvc(
            @RequestParam("name") String name,
            @RequestParam("pageIndex") Integer pageIndex,
            @RequestParam("pageSize") Integer pageSize, Model map) throws Exception {
        User user=new User();
        user.setName(name);
        userService.add(user);
        PageUtil pageUtil=userService.getUserListByPageUtil(pageIndex,pageSize,user);
        map.addAttribute("pageUtil",pageUtil);
        map.addAttribute("pageIndex",pageIndex);
        return "user/userShow";
    }

show.jsp页面的js,ajax代码

 function search(){
        alert(41234123);
        $.ajax({
            type:"post",
            url:"search",
            //data:$("form").serialize(),
            success : function() {
                alert(2412);
                alert('${pageUtil.totalPages}');
                alert("${pageUtil.totalPages}");
                $("#username").html();
                $("#username").html("${user.name}");
                $("#userage").html("${user.age}");
            }
        });
    };

ajax调用的controller

 @RequestMapping(value="/search", method = {RequestMethod.POST})
    @ResponseBody
    public void search(Model map) throws Exception {
        System.out.println("********************");
        System.out.println(map.containsAttribute("pageUtil"));
        System.out.println(map.containsAttribute("pageIndex"));
        System.out.println(map.asMap().get("pageUtil"));
        System.out.println(map.asMap().get("pageIndex"));
        System.out.println(map.toString());
        System.out.println("********************");
        String search="qinkai0";
        User user=userService.getUserByName(search);
        map.addAttribute("user",user);
    }

下方是结果

 ********************
false
false
null
null
{}
********************

这是两次请求,不同请求传的值,不能共用。建议将第一次请求传的值,保存起来(放入input中),这样可以反复使用