java 何时在 servlet 中调用 doPut()?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10640273/
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-10-31 01:56:12  来源:igfitidea点击:

When is doPut() called in a servlet?

javahttpservlets

提问by Rajeshwar

Hi I was just curious when is the doPut() method in a servlet called. I know that if the form on a jsp/html page has a "post" method then the doPost() is called otherwise if it has a "GET" then the doGet() is called.When is the doPut() called ??

嗨,我只是好奇什么时候调用 servlet 中的 doPut() 方法。我知道如果jsp/html页面上的表单有一个“post”方法,那么doPost()被调用,否则如果它有一个“GET”,那么doGet()被调用。doPut()什么时候被调用??

回答by Matt Ball

When an HTTP PUTrequest is received, naturally.

自然而然地,当收到HTTP PUT请求时。

Can a page do a PUT request by code?

页面可以通过代码执行 PUT 请求吗?

The only valid methodattribute values of a <form>are getand post, according to the HTML5 spec. I assume that's what you're asking.

唯一有效method的属性值<form>getpost根据HTML5规范。我想这就是你要问的。

回答by Lemon Juice

The doPut() method handles requests send by using the HTTP PUT method. The PUT method allows a client to store information on the server. For an example, you can use it to post an image file to the server. As the above answer says, goGet() and doPost() are in use, mostly. In my case, I use only these two, and I am getting only get requests, so I simply transfer the get request to doPost() and do my job easily.

doPut() 方法处理使用 HTTP PUT 方法发送的请求。PUT 方法允许客户端在服务器上存储信息。例如,您可以使用它将图像文件发布到服务器。正如上面的答案所说,主要使用 goGet() 和 doPost() 。就我而言,我只使用这两个,而且我只收到 get 请求,所以我只需将 get 请求转移到 doPost() 并轻松完成我的工作。

回答by Maninder

if you want to send some confidential values in url via form you must use the post method, If you will use the get method for the form like login the values parameters like userid and password will be visible in url and anyone can hack that thing. So better to use post method in forms. By default it will call get method.

如果您想通过表单在 url 中发送一些机密值,您必须使用 post 方法,如果您将像 login 这样的表单使用 get 方法,则用户 ID 和密码等值参数将在 url 中可见,任何人都可以破解那个东西。所以最好在表单中使用 post 方法。默认情况下,它将调用 get 方法。

in get the url is like http://url?method=methodname&userid=123&password=123

so if you use post method the url will be like this http://url/methodname.do