• Post Reply Bookmark Topic Watch Topic
  • New Topic

Communicating through POST

 
Vivian Ryder
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think most servlet communication methods are done through GET. Is there any methods (forward, include?) that communicate through POST? I am curious about this because some servlets are overriden only in either POST or GET, so do I write a generic servlet that can communicate with servlets that were overriden in either POST or GET?

Thank you

Vivian
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets (not HttpServlets) come with the catch-all service() method which is there to handle all possible requests to the servlet, regardless of how the request is made so already is the generic servlet you are after (the clue is in the name of the abstract class javax.servlet.GenericServlet). HttpServlets (and any other servlet implemented for a different protocol) need to implement seperate methods for each type of request they can receive. So an HttpServlet has methods for each of the HTTP requests: PUT, GET, POST, DELETE, TRACE, HEAD and OPTIONS. You could just implement one and have all the others call it, except that what each request type does is different so you need to handle them independently of each other. POST and GET are quite simmilar but there are differences you need to be aware of. For example how you handle a GET request must be idempotent, whereas how you handle a POST request need not be. Or how you recove stuff from the request is different - either using getAttribute or getParameter.
 
Vivian Ryder
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry for not having making my question clear. What I need to know is that most redirections/forwardings in servlets are done through GET. Is there any method that we can send out requests through POST?

Thank you

Vivian
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the methods in java.net.HttpURLConnection
You will find setRequestMethod() which will let you create a POST request.
If you create a connection with a URL that starts "http:" you will get a HttpURLConnection.
A convenient toolkit for control of requests is HttpClient
in the Apache Jakarta project.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!