I want to pass data from one application (Spring MVC) to another application written with ZK Framework using POST request.
One of the parameters of the post method will be a file. Let's call it id
.
So, what I do have now is Composer with the following code:
public class PictureComposer extends SelectorComposer<Component> {
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
Execution e = Executions.getCurrent();
System.out.println("post param: " + Executions.getCurrent().getParameterMap().get("id"));
HttpServletRequest request = (HttpServletRequest) e.getNativeRequest();
String idd = request.getParameter("id");
System.out.println("id: " + idd);
}
}
And, when I try to make a POST request to this composer, Executions.getCurrent().getParameterMap().get("id")
seems to return null
.
Same thing with the second approach (using HttpServletRequest
).
On the other hand, I get some value for id
, when I use GET request and pass this value as a parameter in the URL. But, unfortunately, I cannot pass my file in the URL.
So, the main question is how I can retrieve the variable from the POST request?
UPD: (for now I try to retrieve a plain string parameter, just as simplified example) My POST request looks like this:
POST /zssessentials/picture.zul HTTP/1.1
Host: localhost:8080
Cache-Control: no-cache
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="id"
wooooow
----WebKitFormBoundaryE19zNvXGzXaLvS5C
I've figured out.
The reason was that the servlet didn't parse the multipart requests on its own. I had been sending requests with this line in the header (even if it was plain string or integer values):
Content-type: multipart/form-data
and that was the reason.
So, I was expected to use the third-party library in the PictureComposer
class.
In my case Streaming API from Apache came in handy.
Also, this StackOverflow answer helped me a lot in resolving my problem.