简体   繁体   中英

Can't find service method in Netbeans J2EE project

In NetBeans 6.7.1, I have made a j2ee project,

In this project I have Servlet that extends HttpServlet,
Of whatever little I know about servlets, they should have a service method however in the class in NetBeans I find only thefollowing methods.

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {}
public String getServletInfo() {}

doGet and doPost in call the processRequest method. Where is the service method?

A servlet does not need to (re)implement the service() method of the javax.servlet.Servlet or javax.servlet.http.HttpServlet class. Regurgitating from the API doc, the service() method is used to dispatch requests to the doXXX() methods of the servlet. It is already implemented in the HttpServlet class, for the HTTP protocol, and hence there is no need to override it in another servlet relying on the HTTP protocol.

By the way, NetBeans automatically creates the doGet(), doPost(), getServletInfo() and processRequest() methods for convenience, when you create a servlet. It does not mean that the service() method is not available - most servlet programmers do not have to implement the service() method.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM