5

When do ProcessRequest method called?

I am having a hard time why ,what and how the process request is called? why it is called and how it was called by the servlet container.

GingerHead
  • 8,130
  • 15
  • 59
  • 93
Lego_blocks
  • 301
  • 2
  • 6
  • 15
  • 2
    What `ProcessRequest()` are you talking about? Could you provide an example? – vandale Jul 14 '14 at 15:30
  • 2
    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the http://stackoverflow.com/help/how-to-ask page for help clarifying this question. – Eel Lee Jul 14 '14 at 15:31
  • 1
    So I am generating JSON data from ajax request from a jsp page and calling a doPost method, can I use the ProcessRequest method instead of a doPost? thanks – Lego_blocks Jul 14 '14 at 15:33

2 Answers2

13

The servlet has two important methods for handling the client's request:

1. doPost: in general handles requests coming from forms with post method.

2. doGet: handled requests coming from get method.

Now, ProcessRequest method, is any other method that you can use into your code which is not bound (overridden) to anything.

It is called from the above methods to not complicate the code in them thus the requests are handled in it.

so you can use ProcessRequest to handle your request if and only if it's called from one of the methods above.

GingerHead
  • 8,130
  • 15
  • 59
  • 93
3

The only ProcessRequest I could find, and the example includes this

protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  processRequest(request, response);
}

and

protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  processRequest(request, response);
}

So, it's called when you call it.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249