Hi All,
I am getting multipart null even it is set (ENCODING_MULTIPART) on client side.
I am working with gwt 1.5.3
-------------
My Code
-------------
1. GWT widget: FormHandle
RootPanel rootPanel = RootPanel.get();
final FormPanel form = new FormPanel();
rootPanel.add(form);
form.setAction(GWT.getModuleBaseURL()+"MyFormHandler");
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
.........
.........
.........
panel.add(new Button("Submit", new ClickListener() {
public void onClick(Widget sender) {
form.submit();
}
}));
.........
.........
.........
form.addFormHandler(new FormHandler() {
public void onSubmit(FormSubmitEvent event) {
service.fileUpload(new AsyncCallback(){
public void onFailure(Throwable caught) {
Window.alert("FileUpload Failure!!");
}
public void onSuccess(Object result) {
Window.alert("FileUpload Success!!");
}});
event.setCancelled(true);
}
public void onSubmitComplete(FormSubmitCompleteEvent event) {
Window.alert(event.getResults());
}
});
RootPanel.get().add(form)
2. Servlet:: MyFormHandlerImpl
public class MyFormHandlerImpl extends RemoteServiceServlet implements MyFormHandler {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void fileUpload() {
System.out.println("0");
HttpServletRequest request = super.getThreadLocalRequest();
HttpServletResponse response = super.getThreadLocalResponse();
boolean isMultiPart =
FileUpload.isMultipartContent(request);//isMultipartContent(request)
String parentPath ="d:\\";
if (isMultiPart) {
System.out.println("3");
DiskFileUpload upload = new DiskFileUpload();
try {
List items = upload.parseRequest(request);
Iterator it = items.iterator();
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
if(!item.isFormField()){
File fullFile = new File(item.getName());
File savedFile = new File(parentPath,fullFile.getName());
item.write(savedFile);
}
}
} catch (FileUploadException fUE) {
System.out.println("file not found");
} catch (Exception e){
System.out.println("unknown exception");
}
}
}
}
--------------------------------------------------------------------
Can anybody tell me what i am missing here?
what could be done to resolve this error?
Thanks in advance for your help.
Arun.