PDA

View Full Version : Problems with FileUpLoadField - File is not posted to servlet.



judoOlle
8 Jul 2010, 4:15 AM
Hello!

I'm trying to send a xml file to my servlet using the ExtJS-GWT example about Fileupload.


final com.extjs.gxt.ui.client.widget.Window w = new com.extjs.gxt.ui.client.widget.Window();
w.setSize(400, 150);
w.setPlain(true);
w.setHeading("XML");
// w.setModal(true);
w.setBlinkModal(true);
w.setLayout(new FitLayout());

final com.extjs.gxt.ui.client.widget.form.FormPanel panel = new com.extjs.gxt.ui.client.widget.form.FormPanel();

panel.setHeaderVisible(false);
panel.setFrame(true);
panel.setAction("MyURL");
panel.setEncoding(Encoding.MULTIPART);
panel.setMethod(Method.POST);
panel.setButtonAlign(HorizontalAlignment.CENTER);
// panel.setWidth(350);

final FileUploadField file = new FileUploadField();
file.setAllowBlank(false);
file.setFieldLabel("File");
panel.add(file);

com.extjs.gxt.ui.client.widget.button.Button btn = new com.extjs.gxt.ui.client.widget.button.Button(
"Submit");
btn.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
if (!panel.isValid()) {
return;
}
// handle the post
if (file.getValue().endsWith("xml")) {
panel.submit();
} else {
Window.alert("Not a valid file");
}
}
});
panel.addButton(btn);

w.add(panel);
w.show();When i press the submit button a request is sent to the servlet, however, no file is sent.
When I look at the POSTmessage to the servlet it looks like this:
"-----------------------------30858109968917--".
This message should be followed by the xml-text.


I've tested to create a simple HTML-fileupload page to test the servlet and that works perfectly.

Any ideas what could be wrong? :-?

Many thanks!
/Olle

sven
8 Jul 2010, 6:04 AM
Your file field has no name set. Next time please use the forum search, as this was already answered a couple of times.

judoOlle
25 Jul 2010, 10:47 PM
I did a search but I think my problem differs from the others: I have no problem posting to the servlet, the problem is that my request doesn't seem to include any file information.

As I mentioned earlier I did a html-page with the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test to call Servlet</title>
</head>
<body>
<FORM METHOD=POST ENCTYPE="multipart/form-data"
ACTION="/MyServlet">File to upload: <INPUT
TYPE=FILE NAME="uploadFormElement"><BR>
<INPUT TYPE=SUBMIT VALUE="Submit">
</FORM>

</body>
</html>and this works just the way I want, but it is when I use the GWT-code (in my first post) where I have problems.

I tried to set the name of fileuploadField but it didn't help :(

Is it possible that I could've missed something obvious?

Could the problem be that the panel is added to a window?

Do I need to add the panel to the RootPanel?

judoOlle
26 Jul 2010, 12:14 AM
Oppss, it really was the setName property that was the problem all along.

Sorry! I will be more careful in the future!