I use a HttpServlet to generate an html image dependent on multiple IDs like this:
<img src="./someServlet?ids=123,124,125,126[...]" alt=""/>
someServlet extends from javax.servlet.http.HttpServlet overwriting the doGet()and doPost() methods. It sets the response contenttype to img/png and uses the response outputstream to commit the generated image to the view.
The servlet mapping is done in web.xml:
<servlet>
<servlet-name>SomeServlet</servlet-name>
<servlet-class>my.package.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SomeServlet</servlet-name>
<url-pattern>/someServlet</url-pattern>
</servlet-mapping>
My question: How do I send the request above via POST instead of GET? I tried surrounding it by the <form> tag setting the method to POST, but as expected, it didn’t work.
EDIT: I need this because my request (with 5-10 UUIDS) exceeds the limit of a GET request
You cannot change an
<img>element to send a POST request instead of GET. This makes no sense.As per the comment on the question the query string length limit seems to be the main reason:
Just pass it as part of URL instead, as path info. So, instead of
use
You only need to change your servlet’s URL pattern to
and change the way to obtain the IDs as follows