一个奇怪的servlet 页面递归问题 .
在我的台式机上一显示页面就报错,
可是在我的笔记本上就能显示页面,但 myeclipse 的控制台也报差不多的错,
不过笔记本上也不是总没事,最开始的时候一发布就能显示页面,过了一段时间再发布就不能显示了,只能删了再重新导入就又可以了,好奇怪哦 .
代码如下 :
public class DirList extends HttpServlet{ /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String filePath="c:\\"; if(request.getParameter("filePath")!=null)filePath=request.getParameter("filePath"); this.showDir(filePath,response.getWriter()); } private void showDir(String filePath,PrintWriter write) throws IOException{ File dirFile=new File(filePath); File[] fileList=dirFile.listFiles(); for(int i=0;i<fileList.length;i++){ File fileTmp=fileList[i]; if(fileTmp.isFile()){ write.write(fileTmp.getName()+"<br>"); }else{ write.write("<span>+</span>"+fileTmp.getName()+"<br>"); write.write("<div style='margin-left:10;border:1px red solid;'>"); //就是下面这句,注释掉就不报错了 //this.showDir(fileTmp.getAbsolutePath(), write); } } write.write("</div>"); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); }}