Câu hỏi phỏng vấn Java
Câu hỏi

What is the difference between GenericServlet and HttpServlet ?

Câu trả lời

The primary difference between GenericServlet and HttpServlet lies in their protocol dependency and specific use cases within Java servlet programming.

GenericServlet

GenericServlet is an abstract class that implements the javax.servlet.Servlet interface, making it protocol-independent. This means it can handle any type of protocol such as HTTP, SMTP, FTP, and more. It is designed to be a generic or universal servlet that can be extended to create a custom servlet capable of handling requests and responses according to the needs of different protocols. The service() method in GenericServlet is abstract, and it must be implemented by any subclass to define custom behavior for each protocol[1][2][3][4][5].

HttpServlet

On the other hand, HttpServlet is a subclass of GenericServlet and is specifically designed to handle HTTP requests. It is protocol-dependent, meaning it only processes HTTP requests and responses. HttpServlet provides several methods like doGet(), doPost(), doPut(), and doDelete(), which correspond to the HTTP methods GET, POST, PUT, and DELETE, respectively. These methods provide a framework for handling HTTP-specific interactions, making it easier to develop web applications. Unlike `Gen...

middle

middle

Gợi ý câu hỏi phỏng vấn

junior

Explain Serialization and Deserialization.

middle

How threadsafe is enum in Java?

middle

What is the difference between HashMap , LinkedHashMap and TreeMap in Java?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào