2012-05-13 63 views
0

您好我有一個smartgwt中的listgrid,我需要有一個按鈕來上傳文件到服務器,我創建了一個普通的小服務程序,並已在我的項目的web.xml中聲明,但我不能做到這一點工作,讓我404錯誤部署。你可以使用普通的servlet(使用它的post和get方法)和gwt?smartgwt小服務程序使用

在此先感謝。

回答

0

GWT以一種名爲GWT-RPC的特殊方式在客戶端代碼(GWT編譯的客戶端JS文件)之間傳輸服務器端代碼(運行於servlet容器,如tomcat或jetty)之間的數據&。需要

enter image description here

客戶知道數據的格式,將發送或接收到/從服務器&服務器還必須知道數據的格式,客戶端可以解析(我們有嚴重的侷限性系列化&反序列化的數據,因爲一方我們只有javascript!)。這就是爲什麼你需要爲遠程servlet聲明一個接口& GWT使用它的另一個異步接口&將你的服務調用限制在那個接口上。 &這就是爲什麼你不能在GWT中使用任何標準的servlet。

+0

感謝ü非常...:d – Mariah

0

HttpServlet可與smartgwt一起使用。你需要有DynamicForm並設置.setCanSubmit(true);

示例代碼:

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);