0

Hi I have a listgrid in smartgwt and I need to have a button to upload a file to the server, I created an ordinary servlet and have declared in the web.xml of my project but I can not make it work, make me 404 error to deploy . You can use regular servlets (with its post and get methods) with gwt?

Thanks in advance.

Mariah
  • 1,073
  • 1
  • 14
  • 33

2 Answers2

0

GWT transfers data between server side code (running on servlet container like tomcat or jetty) & client side code (GWT compiled client side JS files) in a special way called GWT-RPC.

enter image description here

Client required to know format of data that will send or receives to/from server & server also must knows about format of data that client can parse(we have serious limitation in serialization & deserialization of data because one side we have only javascript!). This is why you need to declare an interface for your remote servlet & GWT makes another async interface using it & restricts your service calls to that interface. & this is why you can't use any standard servlet with GWT.

Ehsan Khodarahmi
  • 4,772
  • 10
  • 60
  • 87
0

HttpServlet can be used with smartgwt. You need to have DynamicForm and set .setCanSubmit(true);

Sample Code:

final String DEFAULT_FILE_UPLOAD_SERVICE_PATH = "upload";
final String TARGET = "uploadTarget";

VLayout body = new VLayout();

uploadForm = new DynamicForm();

 // initialise the hidden frame
NamedFrame frame = new NamedFrame(TARGET);
frame.setWidth("1px");
frame.setHeight("1px");
frame.setVisible(false);

uploadForm.setEncoding(Encoding.MULTIPART);
uploadForm.setMethod(FormMethod.POST);
// set the (hidden) form target
uploadForm.setTarget(TARGET);

uploadForm.setAction(DEFAULT_FILE_UPLOAD_SERVICE_PATH);

// initialise the File name field
uploadItem = new UploadItem("filename");
uploadItem.setName("filename");
uploadItem.setTitle("File name");

// set the fields into the form
uploadForm.setFields(uploadItem);

// add the Upload Form and the (hidden) Frame to the main layout container
body.addMember(uploadForm);
body.addMember(frame);
Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96