Which open source project have you seen written doGet或doPost是用public? At least I haven't seen it.
The scope of action should be as small as possible (can be used private的就不要用protected,能用protected的就不要用public). This is a principle that needs to be followed in coding.
Access the service method first, and then use the service method to determine whether to use the doget or dopost method. However, the servlet we wrote inherits HttpServlet and rewrites the doget and doPost of the parent class, so we must use public. Java designed this method of increasing permissions so that subclasses can decide whether their methods can be opened to callers. If the subclass is protected, the servlet container can also access it. Generally, the access permissions for overridden parent class methods are >= the parent class's methods.
Which open source project have you seen written
doGet
或doPost
是用public
? At least I haven't seen it.The scope of action should be as small as possible (can be used
private
的就不要用protected
,能用protected
的就不要用public
). This is a principle that needs to be followed in coding.Access the service method first, and then use the service method to determine whether to use the doget or dopost method. However, the servlet we wrote inherits HttpServlet and rewrites the doget and doPost of the parent class, so we must use public. Java designed this method of increasing permissions so that subclasses can decide whether their methods can be opened to callers. If the subclass is protected, the servlet container can also access it. Generally, the access permissions for overridden parent class methods are >= the parent class's methods.