servlet result display in jsp page

后端 未结 3 920
清歌不尽
清歌不尽 2020-12-13 05:08

How to forward the servlet output to jsp page?

That means the result will be displayed in the JSP page.

3条回答
  •  既然无缘
    2020-12-13 05:50

    To forward a request/response from from a servlet to something else (e.g. JSP) you'll want to look at the RequestDispatcher class. The ServletContext class has a method to get a dispatcher, which can be called from within a servlet.

    For example (within a servlet's doPost/doGet method):

    RequestDispatcher rd = getServletConfig().getServletContext()
        .getRequestDispatcher("/jsp/myfile.jsp").forward(request,response);
    

提交回复
热议问题