我想從客戶端發送文件到服務器。formpanel.submit不提交GWT服務器上的文件
我的代碼:
客戶端:
private FormPanel getFormPanel() {
if (formPanel == null) {
formPanel = new FormPanel();
formPanel.setMethod(FormPanel.METHOD_POST);
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
formPanel.setAction(GWT.getHostPageBaseURL() +"UploadFileServlet");
formPanel.setWidget(getFlexTable_1());
System.out.println(GWT.getHostPageBaseURL() +"UploadFileServlet");
}
return formPanel;
}
在getFlexTable_1()
flexTable.setWidget(1, 1, getFileUpload());
在getFileUpload()
private FileUpload getFileUpload() {
if (fileUpload == null) {
fileUpload = new FileUpload();
fileUpload.setName("upload");
}
return fileUpload;
}
private Button getAddButton() {
if (addButton == null) {
addButton = new Button("ADD");
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
formPanel.submit();
}
});
}
return addButton;
}
在服務器端
public class CmisFileUpload extends HttpServlet implements Servlet{
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
byte[] buffer = new byte[115200];//
String fileName = null;
String mimetype = null;
String majorVersion = null;
InputStream stream = null;
System.out.println("ServletWorking Fine");
}
現在,當我選擇一個文件,然後單擊添加按鈕,我看不到服務器端的輸出,該代碼System.out.println("ServletWorking Fine");
關於cl的輸出System.out.println(GWT.getHostPageBaseURL() +"UploadFileServlet");
ient一邊是
http://127.0.0.1:8888/UploadFileServlet
,當我直接在瀏覽器中使用這個網址我得到服務器端輸出System.out.println("ServletWorking Fine");
**
編輯
我創建了一個更Web應用程序的文件上傳
public class Uploadfile implements EntryPoint {
FormPanel uploadForm = new FormPanel();
public void onModuleLoad() {
HorizontalPanel horizontalPanel = new HorizontalPanel();
uploadForm.setAction(GWT.getHostPageBaseURL() +"UploadFileServlet");
uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
uploadForm.setMethod(FormPanel.METHOD_POST);
horizontalPanel.add(uploadForm);
// Create a panel to hold all of the form widgets.
VerticalPanel panel = new VerticalPanel();
uploadForm.setWidget(panel);
FlexTable flexTable = new FlexTable();
panel.add(flexTable);
// Create a FileUpload widget.
FileUpload upload = new FileUpload();
upload.setName("uploadFormElement");
flexTable.setWidget(2, 3, upload);
// panel.add(upload);
// Add a 'submit' button.
Button uploadSubmitButton = new Button("Submit");
panel.add(uploadSubmitButton);
uploadSubmitButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
uploadForm.submit();
}
});
uploadForm.addFormHandler(new FormHandler() {
public void onSubmit(FormSubmitEvent event) {
}
public void onSubmitComplete(FormSubmitCompleteEvent event) {
Window.alert(event.getResults());
}
});
RootPanel.get().add(horizontalPanel);
}
}
服務器
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
System.out.println("working fine");
}
此代碼工作正常
根據我有代碼沒有什麼區別。
PLZ告訴我爲什麼formpanel.submit工作不正常。
Plz help。
你在你的瀏覽器開發者工具看到(。 Firebug或Chrome開發工具或其他瀏覽器中的等價物),在網絡選項卡中?是否發送任何內容?預期的請求?到哪個URL? –
@ThomasBroyer我使用的是Firebug,在networkTab中,網址是127.0.0.1:8888/UploadFileServlet和時間軸只是工作。沒有其他 – NewCodeLearner
@ThomasBroyer在networkTab的網址是127.0.0.1:8888/UploadFileServlet和時間線正常工作。沒有其他 – NewCodeLearner