Java 上载文件时处理网络问题
这里是迄今为止生成的html(使用Java 上载文件时处理网络问题,java,javascript,html,gwt,file-upload,Java,Javascript,Html,Gwt,File Upload,这里是迄今为止生成的html(使用GWT作为前端),这是我迄今为止复制GWT类的html 这相当于 .submit(function(){ //handle file response }) 很好 问题是,如果internet断开连接,在上载文件时,浏览器不会抛出错误/异常/响应 我想通知用户,有一个网络问题 但浏览器会一直提交表单,而不会从该状态返回 有什么提示吗 谢谢您的时间。如果事件为空,是否签入处理程序 form.addSubmitCompleteHandler(new For
GWT
作为前端),这是我迄今为止复制GWT类的html
这相当于
.submit(function(){
//handle file response
})
很好
问题是,如果internet断开连接,在上载文件时,浏览器不会抛出错误/异常/响应
我想通知用户,有一个网络问题
但浏览器会一直提交表单,而不会从该状态返回
有什么提示吗
谢谢您的时间。如果事件为空,是否签入处理程序
form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
public void onSubmitComplete(SubmitCompleteEvent event) {
if(event != null){
Window.alert("Upload OK!");
}else
Window.alert("Upload fail");
});
但我认为如果你有网络问题,SubmitCompleteEvent永远不会被解雇
解决方案可以是在提交文件时设置计时器:
public class ViewWidget {
Form form;
Timer timer = new Timer() {
@Override
public void run() {
Window.alert("Troubles with upload! Try again!");
}
};
public ViewWidget(){
form.addSubmitHandler(new SubmitHandler() {
@Override
public void onSubmit(SubmitEvent event) {
timer.schedule(10000);
}
});
form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
//Cancel the timer
timer.cancel();
if(event != null){
//Do your Stuff
Window.alert("Upload Ok !");
}else
Window.alert("Upload Fails");
}
});
}
我不尝试代码,但它应该可以工作
希望能有帮助
form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
public void onSubmitComplete(SubmitCompleteEvent event) {
if(event != null){
Window.alert("Upload OK!");
}else
Window.alert("Upload fail");
});
public class ViewWidget {
Form form;
Timer timer = new Timer() {
@Override
public void run() {
Window.alert("Troubles with upload! Try again!");
}
};
public ViewWidget(){
form.addSubmitHandler(new SubmitHandler() {
@Override
public void onSubmit(SubmitEvent event) {
timer.schedule(10000);
}
});
form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
//Cancel the timer
timer.cancel();
if(event != null){
//Do your Stuff
Window.alert("Upload Ok !");
}else
Window.alert("Upload Fails");
}
});
}