Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diference doGET doPost and processRequest

 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

is service method like processRequest method?

Is it work in the same way?

Regards, Isaac
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. In fact, the "processRequest pattern" is an anti-pattern where both GET and POST are treated the same way in the servlet. Bad bad practice.

GET and POST should not do the same thing according to the intentions of the HTTP protocol.

While there is a lot to write on the distinction, the stratospheric view is that GET is for getting resources, while POST is for posting operations. That just scratches the surface but shows how treating GET and POST as the same operation is just flat-out wrong.

Caveat: it's a very common mistake and I used to make this poor mistake myself. I now know better.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see you changed your post while I was writing, so my answer doesn't match your new question as well as the former. Please don't do that.

And no, a processRequest is not like service. service is a method in the container that eventually calls on of doGet or doPost. The processRequest is an anti-patterm where the doGet and doPost methods call it, completely losing the distinction between them.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, to make sure that there is no confusion; the processRequest method is not part of the servlet standard but is a method added by some IDEs. It is not something that should ever be used.
 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, another NetBeans user. Bear is correct of course, this is a terrible pattern. I suggest you modify the servlet template. Go to Tools - Templates and then down to Web - Servlet. Choose Open in Editor. My template looks like this. The license section and the getServletInfo() section are optional.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic