• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

processRequest method in servlet

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 7585
176
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic