日期:2014-05-17 浏览次数:21028 次
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);
}
}