I've been writing servlets and filters for years and it is something that has always irked me a little - the checking and casting of ServletRequest
and ServletResponse
parameters to HttpServletRequest
and HttpServletResponse
, particularly with filters as there is no standard HttpFilter
base class to do this for you - unlike servlets.
The question is - when would you ever see anything other that HttpServletRequest
/ HttpServletResponse
being passed to your servlet/filter and what should you do if you do?
在一些尚未实现的世界中,除了HttpServlet之外还有其他servlet类型。
From what I understood going through API, servlet specifications is that the servlet framework has been created for HTTP/web use specifically.
The protocols mentioned under reference section of the servlet specification are all related to HTTP only viz.
RFC 1945 Hypertext Transfer Protocol (HTTP/1.0)
RFC 2616 Hypertext Transfer Protocol (HTTP/1.1)
RFC 2617 HTTP Authentication: Basic and Digest Authentication
RFC 2324 Hypertext Coffee Pot Control Protocol (HTCPCP/1.0) -- this is basd on HTTP
All these are HTTP protocols.
Also the spec mandates this:
All servlet containers must support HTTP as a protocol for requests and responses, but may also support other request / response based protocols such as HTTPS (HTTP over SSL).
And the reason for having GenericServlet -> HttpServlet is to have the Generalization -> towards Specialization kind of hierarchy in the API structure in the API.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.