• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why so many Request method in servlet API

 
Rajeev roushan sharma
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All, I have one doubt, why there are 7 request methods(like doGet,doPost etc..) are available in Servlet API ? if we want to write logic based on request method then we have httprequest.getMethod(). JSP is finally converted into a servlet class but there is no request methods. I know that JSP is used as view and servlet is used as controller.

Thanks in advance!

Best regards,
rS
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should never be addressing a JSP directly with an HTTP request. Requests should always be made to servlets. There is no need for HTTP method handling in a JSP.
 
Rajeev roushan sharma
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. The other question is why separate methods are there in SEEVLET api for each request method ? could you please clarify this also ?

 
Paul Clapham
Sheriff
Posts: 21551
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajeev roushan sharma wrote:Hi All, I have one doubt, why there are 7 request methods(like doGet,doPost etc..) are available in Servlet API ? if we want to write logic based on request method then we have httprequest.getMethod().


There shouldn't be any cases where you want to write logic which differs based on the request method. If your design says that a URL should be accessed via the GET method, then you implement doGet. And if your design says that a URL should be accessed via the POST method, then you implement doPost. This will cause the container to automatically reject requests which use the wrong method, i.e. you don't need to write code to do that yourself.

I suppose there might be systems which want to treat GET requests differently than POST requests. In that case you would implement doGet to process the GET requests and doPost to process the POST requests. But treating GET and POST identically is just sloppy design.
 
Rajeev roushan sharma
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, I got your point. I have seen service method implementation in httpservlet class. Ultimately doGet or doPost etc is called on request method. Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic