java - request.getRequestDispatcher jumps, and the log also indicates that view (jsp) is accessed, but the browser does not move.
欧阳克
欧阳克 2017-06-12 09:22:12
0
2
819

1. The springmvc filter request.getRequestDispatcher jumped, and the log also indicated that the view (jsp) was accessed, but the browser did not move.

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

There is a function request on the page to request the controller through jquery ajax. The filter finds that there is no login. The filter request.getRequestDispatcher initiates a login request and jumps to the login page. The log record has been forwarded (see Figure 2), but the browser does not jump.

2. And it’s no problem to request /toLogin alone, just come out to the login page

欧阳克
欧阳克

温故而知新,可以为师矣。 博客:www.ouyangke.com

reply all(2)
给我你的怀抱

When making an AJAX request, the page you return will be used as data using XMLHttpRequest.responseText to receive it.
The correct approach should be that if the background finds that the conditions for successful login are not met, return an unsuccessful flag to AJAX (for example: {"login" : "failed"}), and then the front-end determines if it is this flag, then pass window.location.href Jump to the "/toLogin" page you defined.

phpcn_u1582

Ajax jumps using js, and form submission uses your method

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template