账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    SSM中页面跳转时,通过model.addAttribute传递的数据出现在URL中
    53
    0
    if(user == null) {
                model.addAttribute("error","帐号或密码错误");
                return "redirect:/login/ulogin";
            }else{
                model.addAttribute("uName",user.getUserName());
                return "redirect:/index/";
            }
            
            
      http://localhost:8080/quella/index/?uName=aaa      在index.jsp获取不到uName的值,它却出现在了URL中
            
          
    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 我美跟我走 普通会员 1楼

      在Spring MVC中,通过model.addAttribute()方法传递的数据并不会直接出现在URL中,它是在服务器端将数据添加到Model对象中,然后在目标视图页面中可以通过EL表达式或者Controller方法的ModelAttribute参数来获取这些数据。

      如果你发现数据出现在了URL中,那可能是你在进行重定向(Redirect)操作时,使用了RedirectAttributes对象的addAttribute()方法,这种情况下,Spring会将这些属性作为查询参数附加到重定向URL后面。

      例如:

      java @RequestMapping("someAction") public String handleRequest(Model model, RedirectAttributes redirectAttributes) { redirectAttributes.addAttribute("key", "value"); return "redirect:someOtherPage"; }

      在这个例子中,"key=value"将会被追加到重定向的URL后面。如果你想在页面跳转时避免这种情况,确保你使用的只是Model对象而非RedirectAttributes来进行非重定向的视图渲染。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部