• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

GWT fileuploading error

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am also getting following error/exception...

SEVERE: Exception while dispatching incoming RPC call
javax.servlet.ServletException: Content-Type was 'multipart/form-data;
boundary=---------------------------24626113235537'. Expected 'text/x-gwt-rpc'.
at
com.google.gwt.user.server.rpc.RPCServletUtils.checkContentType(RPCServletUtils.java:318)
at
com.google.gwt.user.server.rpc.RPCServletUtils.readContentAsUtf8(RPCServletUtils.java:135)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.readContent(RemoteServiceServlet.java:335)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:77)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


-------------
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.
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic