springmvc重定向和轉發,配置試圖基礎上

    /**
     * 測試重定向
     */
    @RequestMapping(value="/testRedirectOrForward.do",method = RequestMethod.GET)
    public String redirect(@RequestParam("id")int id){
        if(id==1){
            log.info("{}重定向",id);
            return "redirect:/static/redirect.jsp";
        }else{
            log.info("{}轉發",id);
            return "forward:/static/forward.jsp";
        }
    }
    @RequestMapping(value="/test.do",method = RequestMethod.GET)
    public String red(@RequestParam("id") int id){
        if(id==1){
            return  "redirect:/student/testRedirectOrForward.do?id="+id;
        }else{
            return "forward:/student/testRedirectOrForward.do?id="+id;
        }
    }

瀏覽器中輸入ip: http://localhost:8080/student/test.do?id=1
id=1的話會重定向,地址欄會變,不安全
這裏寫圖片描述
id不是1的話是轉發
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章