response.sendRedirect not working

前端 未结 4 1019
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-21 00:42

The method response.sendRedirect() is not working in my program.

The code go through and sucessfully print out.println(\"wrong user\");, but the redirec

相关标签:
4条回答
  • 2020-12-21 01:10

    HttpServletResponse.sendRedirect() works like this:

    • if the URL is absolute http://www.google.com , it redirects to http://www.google.com.
    • If the URL is not absolute , it redirects relative to the current URL. If the URL starts with / it redirects relative to the context root, Else it redirects to the current url

    Based on above rules in your case it redirects to http://currenturl/www.google.com.

    Instead modify your code like this

    response.sendRedirect("http://www.google.com");
    return;
    
    0 讨论(0)
  • 2020-12-21 01:19

    Try providing the protocol.

    response.sendRedirect("http://www.google.com");
    return;
    
    0 讨论(0)
  • 2020-12-21 01:21

    You should return after redirecting.

    response.sendRedirect("http://www.google.com");
    return;
    

    It does not return automatically after calling sendRedirect().

    0 讨论(0)
  • 2020-12-21 01:25

    Try this

    <% response.sendRedirect("http://www.google.com/"); %>
    
    0 讨论(0)
提交回复
热议问题