首頁  >  問答  >  主體

java - request.getRequestDispatcher跳轉了,日誌也提示view(jsp)訪問了,瀏覽器卻沒動靜

1、springmvc過濾器request.getRequestDispatcher跳轉了,日誌也提示view(jsp)訪問了,瀏覽器卻沒動靜。

#
if(!isLogin){
            httpServletRequest.getRequestDispatcher("/toLogin").forward(httpServletRequest, httpServletResponse);
        }

#
17:57:55.062 [http-nio-8080-exec-3] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'indexLogin'
17:57:55.062 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/toLogin] is: -1
17:57:55.063 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'login'; URL [/WEB-INF/view/login.jsp]] in DispatcherServlet with name 'springMVC'
17:57:55.063 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/view/login.jsp] in InternalResourceView 'login'
17:57:55.064 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request

頁面有個功能請求透過jquery ajax去請求controller,過濾器發現沒登入過濾器request.getRequestDispatcher發起登入請求跳到登入頁面,日誌記錄已經forward了(看圖2),但瀏覽器沒跳。

2、而且單獨請求/toLogin沒問題,直接出來登入頁面

欧阳克欧阳克2686 天前787

全部回覆(2)我來回復

  • 给我你的怀抱

    给我你的怀抱2017-06-12 09:24:12

    AJAX 請求的時候,會將你回傳的頁面當成是資料使用 XMLHttpRequest.responseText 去接收。
    正確的做法應該是如果後台發現不滿足登入成功的條件,回傳一個不成功的標誌給AJAX(例如:{"login" : "failed"}),然後前端判斷如果是這個標誌,那麼透過window.location.href 跳到你定義的「/toLogin」 頁面。

    回覆
    0
  • phpcn_u1582

    phpcn_u15822017-06-12 09:24:12

    Ajax用js方式跳,form表單提交用你這種方式

    回覆
    0
  • 取消回覆