简体   繁体   English

我们可以从img标签src调用servlet的doPost方法吗?

[英]Can we call doPost method of servlet from img tag src?

i know it does not make any sense calling doPost method of servlet from img tag src: 我知道从img标签src调用servlet的doPost方法没有任何意义:

  <img src='/ServletName' alt=''/>// i know it will call doGet or service method but i can't use these.

So is there any way calling doPost method from img tag of html and show image in img tag? 那么有什么方法可以从html的img标签调用doPost方法并在img标签中显示图像?

Actually my doPost method response type is : 实际上我的doPost方法响应类型是:

  response.setContentType("image/jpeg");

also i cannot store image on disk of server. 我也不能在服务器磁盘上存储图像。

So is there any way calling doPost method from img tag of html and show image in img tag? 那么有什么方法可以从html的img标签调用doPost方法并在img标签中显示图像?

No. That's just the contract of HTML <img> element. 不,那只是HTML <img>元素的约定。 The webbrowser must download the image by a GET request on the URL as specified in src attribute. Web浏览器必须通过src属性中指定的URL上的GET请求下载图像。

Just do the image serving job in doGet() method instead. 只需在doGet()方法中执行图像服务即可。 Even more, you can just rename doPost to doGet . 甚至更多,您可以将doPost重命名为doGet The logic doesn't need to be changed at all. 逻辑根本不需要更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM