• Post Reply Bookmark Topic Watch Topic
  • New Topic

processRequest method in servlet

 
Divya Janyavula
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have created a Servlet using NetBeans IDE. The generated code contains processRequest method. I checked this method and did not find it in Servlet API. Is it fine to use this method to handle GET and POST requests.

How this actually works. Any link to the same is appreciated.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
processRequest is just a name like another, you could call it processMyRequests or as you like it.
And it's fine to use this method to handle GET and POST requests, but don't look for it in Servlet API because you won't find it
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't matter what IDE you use. It doesn't even matter if you don't use an IDE. The J2EE servlet API doesn't have anything to do with IDEs. It cannot, since there's no IDE on a production server.

On the other hand, the servlet API does provide a "service()" method and all incoming HTTP service requests for that servlet's URL pattern will be sent to it.

You can override the service() method if you want. The HttpServletRequest class does so in order to route GET requests to an API-defined doGet() method and POST requests go to doPost().
 
Divya Janyavula
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got confused as the doGet, doPost implementations were folded by NetBeans. I realized that doGet/doPost will call this processRequest method.

Thanks for the replies.
 
Tim Moores
Saloon Keeper
Posts: 3250
54
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two points to note. Firstly, having doGet and doPost both call the same method is very bad practice. It violates the HTTP specification which states clearly that GET and POST are not to be used interchangeably. Secondly, do not override the service method, for the same reason. The service method is specifically there to differentiate between the different HTTP methods, and there are extremely few legitimate reasons why you would want to override it (and what you describe is no such case).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!