1.用js判断:
//判断服务器上的文件是否存在
// function IsExistsFile(filepath){
// var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
// xmlhttp.open("GET",filepath,false);
// xmlhttp.send();
// if(xmlhttp.readyState==4){
// if(xmlhttp.status==200) return true; //url存在
// else if(xmlhttp.status==404) return false; //url不存在
// else return false;//其他状态
// }
//}
2.在java里判断
public String checkFile(){
String url=request.getParameter("url");
URL serverUrl;
try {
serverUrl = new URL(url);
HttpURLConnection urlcon = (HttpURLConnection) serverUrl.openConnection();
message = urlcon.getHeaderField(0);
System.out.println(message);
} catch (Exception e) {
e.printStackTrace();
}
return "message";
}