ServletContext.getRequestDispatcher() vs ServletRequest.getRequestDispatcher()

后端 未结 6 1901
别跟我提以往
别跟我提以往 2020-12-02 15:58

why

getRequestDispatcher(String path) of the ServletRequest interface cannot extend outside the current servlet context

<
6条回答
  •  自闭症患者
    2020-12-02 16:27

    request.getRequestDispatcher(“url”) means the dispatch is relative to the current HTTP request.Means this is for chaining two servlets with in the same web application Example

    RequestDispatcher reqDispObj = request.getRequestDispatcher("/home.jsp");
    

    getServletContext().getRequestDispatcher(“url”) means the dispatch is relative to the root of the ServletContext.Means this is for chaining two web applications with in the same server/two different servers

    Example

    RequestDispatcher reqDispObj = getServletContext().getRequestDispatcher("/ContextRoot/home.jsp");
    

提交回复
热议问题