笔记18 客户端跳转
生活随笔
收集整理的這篇文章主要介紹了
笔记18 客户端跳转
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在前面的例子中,無論是/index跳轉到index.jsp 還是/addProduct 跳轉到showProduct.jsp,都是服務器跳轉。?
本例講解如何進行客戶端跳轉
1.修改IndexController
首先映射/jump到jump()方法
在jump()中編寫如下代碼:ModelAndView mav = new ModelAndView("redirect:/index");
redirect:/index:即表示客戶端跳轉的意思
?
1 package controller; 2 3 import javax.servlet.http.HttpServletRequest; 4 import javax.servlet.http.HttpServletResponse; 5 6 import org.springframework.stereotype.Controller; 7 import org.springframework.web.bind.annotation.RequestMapping; 8 import org.springframework.web.servlet.ModelAndView; 9 10 @Controller 11 public class IndexController { 12 @RequestMapping("/index") 13 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { 14 15 ModelAndView mav = new ModelAndView("index"); 16 mav.addObject("message", "Hello Spring MVC——————客戶端跳轉"); 17 return mav; 18 } 19 20 @RequestMapping("/jump") 21 public ModelAndView jump() { 22 ModelAndView mav = new ModelAndView("redirect:/index"); 23 return mav; 24 } 25 }2.測試
訪問頁面:http://localhost:8080/MySpringMVC5/jump
結果客戶端跳轉到了:http://localhost:8080/MySpringMVC5/index
?
轉載于:https://www.cnblogs.com/lyj-gyq/p/8909956.html
總結
以上是生活随笔為你收集整理的笔记18 客户端跳转的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于Nginx+FastDFS搭建图片文
- 下一篇: 修改bootstrap modal模态框