Home  >  Q&A  >  body text

java - request.getRequestDispatcher jumps, and the log also indicates that view (jsp) is accessed, but the browser does not move.

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

欧阳克欧阳克2686 days ago785

reply all(2)I'll reply

  • 给我你的怀抱

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

    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.

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-06-12 09:24:12

    Ajax jumps using js, and form submission uses your method

    reply
    0
  • Cancelreply