如果登錄成功,會重定向到系統首頁 response.sendRedirect("jsp/frame.jsp"); 在springmvc中,應該如何處理?是否可以直接使用 return "frame"; 來進行頁面的重定向?
一般情況下,控制器方法返回的字符串會被當成邏輯視圖嗎處理,這僅僅是驚醒服務端的頁面跳轉而已,並非客戶端重新發送新的url請求,若想進行重定向操作,就需要加入 redirect: 前綴,springmvc將對它進行特殊處理,將 redirect: 當作指示符,其后的字符串作為url處理。如下
@RequestMapping(value = "/dologin.html", method = RequestMethod.POST) public String doLogin(@RequestParam String userCode, @RequestParam String userPassword){ //省略 return "redirect:/user/main.html"; //response.sendRedirect("jsp/frame.jsp"); }