方法链接如何工作? [英] How does method chaining work?
本文介绍了方法链接如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的示例中,如何从getServletContext()
调用getRequestDispatcher("xxx")
?这样的调用过程通常如何工作?请给我有关此情况的清晰图片.
How does getRequestDispatcher("xxx")
get called from getServletContext()
in the example below? How does calling procedures like this work in general? Please give me a clear picture about this context.
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
dispatcher.include(request, response);
推荐答案
getServletContext()
返回ServletContext
对象,该对象具有称为getRequestDispatcher()
的方法.您的代码行只是两个方法调用的简写,等效于以下代码:
getServletContext()
returns a ServletContext
object, which has a method called getRequestDispatcher()
. Your line of code is just shorthand for two method calls, and is equivalent to this code:
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/index.jsp");
这篇关于方法链接如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文