Pass Hidden parameters using response.sendRedirect()

后端 未结 4 528
天涯浪人
天涯浪人 2020-11-28 06:22

How would I pass hidden parameters? I want to call a page (test.jsp) but also pass 2 hidden parameters like a post.

response.sendRedirect(\"/content/test.jsp         


        
4条回答
  •  误落风尘
    2020-11-28 07:03

    Generally, you cannot send a POST request using sendRedirect() method. You can use RequestDispatcher to forward() requests with parameters within the same web application, same context.

    RequestDispatcher dispatcher = servletContext().getRequestDispatcher("test.jsp");
    dispatcher.forward(request, response);
    

    The HTTP spec states that all redirects must be in the form of a GET (or HEAD). You can consider encrypting your query string parameters if security is an issue. Another way is you can POST to the target by having a hidden form with method POST and submitting it with javascript when the page is loaded.

提交回复
热议问题