redirect jsp from servlet RequestDispatcher

后端 未结 5 1834
傲寒
傲寒 2020-12-03 15:59

I want to redirect JSP page from one servlet. All JSP pages are under Web Content. not under Web-INF. I have a problem of calling that JSP pages.

相关标签:
5条回答
  • 2020-12-03 16:06

    This error occurs when you have an error in java scriptlet of your jsp you've forwarded your request to.
    For example I was calling <% request.getAttribute("user"); %> whereas the problem solved when I used <% request.getParameter("user") %>

    0 讨论(0)
  • 2020-12-03 16:09

    A slightly cleaner way to write this code is:

    request.getRequestDispatcher("/thankyou.jsp").forward(request, response);
    
    0 讨论(0)
  • 2020-12-03 16:17

    I solved the problem using RequestDispatcher like this:

    RequestDispatcher requestDispatcher; 
    requestDispatcher = request.getRequestDispatcher("/thankYou.jsp");
    requestDispatcher.forward(request, response);
    
    0 讨论(0)
  • 2020-12-03 16:23

    Better way to use 'sendRedirect()' method using response object.

    you can write like

     response.sendRedirect("./newpage.jsp");
    

    This will send control to your 'newpage.jsp' page.

    0 讨论(0)
  • 2020-12-03 16:24

    Use SendDirect if you want to work with JSP pages

    response.sendRedirect("/thankyou.jsp");
    

    This is simpe thing to use than RequestDispatcher which doesn't work with doPost().

    0 讨论(0)
提交回复
热议问题