request requires Incoming folder path
This is the backstage code.
ImportJava.io.File;Importjava.io.IOException;Importjava.net.MalformedURLException;Importjava.util.ArrayList;Importjavax.servlet.ServletException;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.ResponseBody;/*** File Preview helper class *@authorzhy**/@Controller Public classFilebrowseutil {/*** Get an filelist array of files in the incoming file path via AJAX request *@paramreq *@paramRESP *@paramParams folder Path parameter *@return * @throwsservletexception *@throwsIOException *@throwsmalformedurlexception*/@RequestMapping ("/getfilelist") @ResponseBodyprotectedArraylist<string>Calculategeoservlet (httpservletrequest req, httpservletresponse resp,string params)throwsservletexception, IOException, malformedurlexception {ArrayList<String> filelist=NewArraylist<string>(); String dir=req.getsession (). Getservletcontext (). Getrealpath (params); FileList=GetFiles (dir); returnfileList; } /*** Recursively get all the directories and their files under a certain path *@paramfilePath File path *@return */ PublicArraylist<string>getFiles (String filePath) {ArrayList<String> fileList =NewArraylist<string>(); File Root=NewFile (FilePath); file[] Files=Root.listfiles (); for(File file:files) {if(File.isdirectory ()) {/** Recursive invocation*/GetFiles (File.getabsolutepath ()); Filelist.add (File.getabsolutepath ()); } Else{String Picpathstr=File.getabsolutepath ();//String picpathstr = File.getabsolutepath (). ReplaceAll ("\\\\", "//");Filelist.add (Getfilenamewithsuffix (PICPATHSTR)); } } /*For (String str:filelist) {System.out.println (str); }*/ returnfileList; } /*** reserved file name and suffix*/ Publicstring Getfilenamewithsuffix (String pathandname) {intStart = Pathandname.lastindexof ("\ \"); if(Start! =-1 ) { returnPathandname.substring (start + 1)); } Else { return NULL; } } /*** Reserved filenames only do not retain suffixes*/ Publicstring GetFileName (String pathandname) {intStart = Pathandname.lastindexof ("\ \"); intEnd = Pathandname.lastindexof ("."); if(Start! =-1 && End! =-1) { returnPathandname.substring (start + 1), end); } Else { return NULL; } } }
Read all files under static resource files in the project, such as all pictures