Hi,
my English is not very good, please be understanding
I try to make an FileUpload
when I press the submitbutton,
the server code is called and executed, but it did not get the file
that I want to upload
I tested it with a normal htmlformular whether any data arriving
as they arrive in this way, I think that the error is on the client
side, but I can not find any error
Here is my code
serverside:
public class UploadFileServlet extends HttpServlet implements Servlet
{
private static final long serialVersionUID = 1L;
private static final Logger logger =
Logger.getLogger(UploadFileServlet.class);
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("text/plain");
FileItem uploadItem = null;
try {
uploadItem = getFileItem(request);
} catch (Exception e) {
e.printStackTrace();
}
if (uploadItem == null) {
response.getWriter().write("NO-SCRIPT-DATA");
return;
}
byte[] fileContents = uploadItem.get();
//TODO: add code to process file contents here. We
will just print it.
System.out.println(new String(fileContents));
response.getWriter().write(new String(fileContents));
}
private FileItem getFileItem(HttpServletRequest request) throws
Exception {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new
ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(request);
Iterator<FileItem> it = items.iterator();
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
if (!item.isFormField() &&
"uploadFormElement".equals(item.getFieldName())) {
return item;
}
}
return null;
}
Client-side:
private void uploadpanel() {
popup.clear();
// uploadsets
form.setAction(GWT.getModuleBaseURL() + "UploadFileServlet");
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
form.setWidget(uploadpanel);
final TextBox tb = new TextBox();
tb.setName("Testing");
uploadpanel.add(tb);
// Create a FileUpload widget.
FileUpload upload = new FileUpload();
upload.ensureDebugId("uploadFormElement");
upload.setName("uploadFormElement");
uploadpanel.add(upload);
// Add a 'submit' button.
Button submit = new Button("Submit");
submit.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
form.submit();
popup.remove(uploadpanel);
popup.hide();
uploadpanel.clear();
};
});
Button cancel = new Button("Cancel");
cancel.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
popup.remove(uploadpanel);
popup.hide();
popup.clear();
uploadpanel.clear();
};
});
});
uploadpanel.add(submit);
uploadpanel.add(cancel);
popup.add(uploadpanel);
popup.show();
}
i hope that someone can helps me
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.