首页 > 代码库 > Ajax请求访问action判断文件是否存在

Ajax请求访问action判断文件是否存在

action中的写法:

public ActionForward fileIsExsit(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) {
String url = request.getParameter("loadFile");
File file = new File(request.getServletContext().getRealPath("/") + url);
response.setCharacterEncoding("utf-8");


PrintWriter out;
try {
out = response.getWriter();
if (!file.exists()) {
out.print("no");
}


out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}


return null;

}

页面中js的写法:

//验证文件是否存在
function valFile(url){
$.post(url,{参数李彪},function(result){  
       alert(result);
       
 });  
}

Ajax请求访问action判断文件是否存在