why do we use ServletResponse object reference to call getWriter()

servlets

31 просмотра

1 ответ

Why do we use ServletResponse object reference to call getWriter() method?

protected void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException {
    PrintWriter pw=res.getWriter();
    res.setContentType("text/html");
Автор: prasaad chandrashekhar Источник Размещён: 08.11.2019 10:58

Ответы (1)


1 плюс

Your question doesn't give much information. So I am just guessing what you need.

HttpServletResponse is an interface belonging to the javax.servlet.http package. It's super-interface ServletResponse declares the getWriter() method. Hence it is inherited by HttpServletResponse.

We can use an interface's reference to call a method on an object whose class implements the said interface. Hence we can call getWriter() on a reference of HttpServletResponse.

Автор: linuxartisan Размещён: 20.08.2016 07:05
Вопросы из категории :
32x32