Java 处理请求方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24740077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:34:30  来源:igfitidea点击:

ProcessRequest Method

javaservlets

提问by Lego_blocks

When do ProcessRequest method called?

ProcessRequest 方法何时调用?

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.

我很难为什么,什么以及如何调用流程请求?为什么调用它以及它是如何被 servlet 容器调用的。

采纳答案by GingerHead

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

servlet具有处理客户端的请求两个重要的方法:

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

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

2. doGet: handled requests coming from get method.

2. doGet: handled requests coming from get method.

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

现在,ProcessRequest方法是您可以在代码中使用的任何其他方法,它没有绑定(覆盖)到任何东西。

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 ProcessRequestto handle your request if and only ifit's called from one of the methods above.

因此,当且仅当从上述方法之一调用它时,您才能使用它ProcessRequest来处理您的请求。

回答by Elliott Frisch

The only ProcessRequestI could find, and the example includes this

我能找到的唯一ProcessRequest,这个例子包括这个

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.

所以,当你调用它时它被调用。