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); }); }