0

I have a client-side GWT-FormPanel, which has an import file functionality. I want to pass cookie along with the form to the action on the server-side.

I tried this method: Passing parameters along with a multipart/form-data upload form (Java Http Post Upload)

I tried adding a hidden variable as well. But it does not seem to work with ENCODING_MULTIPART.

However I am concerned I have to pass multiple variables, is this method to go about the problem?

final FormPanel form = new FormPanel();
        form.setAction("./abc/sheets/importReport");
        form.setMethod(FormPanel.METHOD_POST);
        form.setEncoding(FormPanel.ENCODING_MULTIPART);

Is there any other method to pass parameters from the client to the server in the Http request?

Can anyone help me out? Thanks in Advance.

  • 3
    did you try just adding a hidden field to the FormPanel? http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/Hidden.html – Marc Stroebel Sep 09 '19 at 11:53
  • I tried this just now and its working, Though I have one doubt, I have a HorizontalPanel where in the upload buttons are. This HorizontalPanel is inside a verticalPanel which is inside the FormPanel(mentioned in the original question). If I add my hidden widget to the FormPanel it fails and if I add it to the Lowest panel with the upload buttons it works. Can you explain why is this happening? Thanks in Advance :) – Shubham Kumar Sep 09 '19 at 12:13
  • 4
    FormPanel extends SimplePanel, so it can only wrap one widget. In your case the panel, so you need to add the hidden field to one of your panels – Marc Stroebel Sep 09 '19 at 12:19
  • @MarcStröbel Thanks for your quick and apt reply! – Shubham Kumar Sep 10 '19 at 05:13
  • @MarcStröbel If I use form encoding as ENCODING_MULTIPART. I cannot use the hidden variable method. Is there some workaround to use ENCODING_MULTIPART and not add the parameter in the url? – Shubham Kumar Sep 10 '19 at 06:45
  • 1
    why can't you use ENCODING_MULTIPART? you will get 2 parts in your request, one for the file and one for your form data (hidden field). What's your server side build on? – Marc Stroebel Sep 10 '19 at 06:57
  • Server is written in Java, I am using request.getParameter() to read the hidden value on the server-side. – Shubham Kumar Sep 10 '19 at 08:25
  • look e.g. here how to handle multipart uploads : https://stackoverflow.com/questions/2422468/how-to-upload-files-to-server-using-jsp-servlet – Marc Stroebel Sep 10 '19 at 08:31
  • Thanks a ton! :) – Shubham Kumar Sep 10 '19 at 13:14

0 Answers0