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

时间:2023-01-26 23:20:44
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);

       

 });  

}

版权声明:本文博主原创文章。博客,未经同意不得转载。