Servelet: package com.syit.scmis.common;
Import java.io.ioException; import javax.servlet.servlet; import javax.servlet.servletException;
Import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletRequest; import javax.servlet.http.httpservletResponse;
/ ** * @version 1.0 * @Author * / public class getfile extends httpservlet imports servlet {
/ ** * @see javax.servlet.http.HttpServlet # void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) * / public void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doPost (REQ, RESP);
/ ** * @see javax.servlet.http.HttpServlet # void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) * / public void doPost (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {req .SetCharacterencoding ("GBK"); string spath = req.getParameter ("path"); if (Spath.equals ("))) {java.io.printwriter out = resp.getwriter (); out.println (" Current " Directory is invalidate! ");} else {if (Spath.indexOf (" / down ") == 0) {Req.setttribute (" Parent ", spath.substring (1)); spath = getServletContext (). getRealPath ( Spath); Downloadfile F = New Downloadfile (); if (F.GetfileEx (Spath, Req, Res) == 1) {Req.getRequestDispatcher ("/ Download.jsp"). Forward (Req, Resp);}} Else {Java.io.printwriter out = resp.getwriter (); out.println ("current directory is invalidate!");}}}
} Main work Java class: / * * Create date 2004-10-13 * * / package com.syit.scmis.common;
Import java.io. *; import java.util. *; import javax.servlet.http. *;
/ ** * * @author Fuqiming * @version 1.0 * * / public class DownloadFile {public int getFileEx (String strpath, HttpServletRequest req, HttpServletResponse resp) throws IOException {File f = new File (strpath); if (f.isDirectory ( )) {Req.setttribute ("List", getfile (strpath)); returnif 1;} else if (f.isfile ()) {DOWNFILE (StrPath, Req, Resp); return 0;} else {throw new oException "path is invalidate");}} public arraylist getfile (string strpath) {ArrayList array = new arraylist (); file f = file (strpath); file [] fs = f.listfiles (); for (int i = 0; i