I´m trying to catch the next two highlighted fields in a servlet where I can get the uploaded file.
The source code is just the same as which is shown in a GWT FormSubmit class Javadoc
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
// Create a panel to hold all of the form widgets.
VerticalPanel panel = new VerticalPanel();
form.setWidget(panel);
// Create a TextBox, giving it a name so that it will be submitted.
final TextBox tb = new TextBox();
tb.setName("WorkTitle");
tb.setValue("WorkTitle");
panel.add(tb);
// Create a ListBox, giving it a name and some values to be associated
// with
// its options.
ListBox lb = new ListBox();
lb.setName("listBoxFormElement");
lb.addItem("foo", "fooValue");
lb.addItem("bar", "barValue");
lb.addItem("baz", "bazValue");
panel.add(lb);
// Create a FileUpload widget.
FileUpload upload = new FileUpload();
upload.setName("uploadFormElement");
panel.add(upload);
// Add a 'submit' button.
panel.add(new Button("Submit", new ClickListener() {
public void onClick(Widget sender) {
form.setAction(GWT.getModuleBaseURL()+"uploadWork");
form.submit();
}
}));
I´m getting these parameters with this code lines in my servlet:
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("ENTRAA BIENNNN");
System.out.println(" ___ELEMENTO1" + req.getAttribute("WorkTitle"));
System.out.println(" ___ELEMENTO3" + req.getParameterValues("WorkTitle"));
But both returns me NULL.
How could I do?
TIA!
Most servlet containers do not decode
multipart/form-dataautomatically, soreq.getParameter(orgetParameterValuesor similar getters) won’t return anything.You’ll have to use a library such as Apache Commons FileUpload, or Jetty’s
MultiPartFilterto decodemultipart/form-datapayload.As a side note,
req.getAttributehas nothing to do with getting data out of the request; it’s used to pass data, related to a request, between server components (between the servlet container and servlets, or between a filter and a servlet, for instance)