You need to create and send the HTTP request yourself. You cannot use forward / redirect / include because you want to change the method from GET to POST and want to send a multipart/form-data
request.
As the HttpClient (and another third-party library?) Is apparently not an option, it is best to use the standard Java SE API provided by java.net.URLConnection
. In short: Using java.net.URLConnection to start and process HTTP requests Below you can find an example of multipart/form-data
.
Please note that this problem does not apply to servlets. In other words, you should be able to execute this code in a simple Java application using the main()
method. This simplifies testing and finalization. Once you earn it, just let the servlet execute the same piece of code.
Not related to the problem, I got the impression that somewhere there was a serious design failure, of course, if both servlets work in the same context of web applications. The other servlet that you want to send the POST request to is apparently too tightly coupled and needs to be reorganized.
source share