Why I am writing this blog? In network some times we don't have server/FTP server(I personally think that it is not more interactive, i.e it can't be in a form of web page) and we have to share any file/s to more than 50 people, then we stuck in messages like "No more connections can be made.. bla bla bla" or either network restriction policy don't allow to do so. Apart from this there may be other issues that can stop to access shared folders in network. I have seen all these kind of problem in accessing shared documents.
So I tried to make web page like application where user can view and download their files via web page. For that you require obviously Tomcat Server for running JSP pages.
So, you should have working knowledge of Tomcat Server.
Create a JSP page and save in your project directory and use this code.
<p><%
File folder = new File("G:\\tomcatserver\\webapps\\softshare\\share\\fonts");
File[] listOfFiles = folder.listFiles();
%><table><%
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String pp="share/fonts/"+listOfFiles[i].getName();
%><tr><td width="500px"><a href="<%=pp%>"><%=listOfFiles[i].getName()%></a><%
%></td><td><%
Path path=Paths.get(listOfFiles[i].getPath());
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
out.println(attr.creationTime().toString().substring(0,10));
out.println(" </td></tr>");
}
}
%></table><%
%></p>
Now lets see the code in details-
File folder = new File("G:\\tomcatserver\\webapps\\softshare\\share\\fonts"); //path of folder
File[] listOfFiles = folder.listFiles(); // will store file in array.
This code will read the files of fonts/ folder. The font folder should be in your project directory, it should not be out your tomcat server.
String pp="share/fonts/"+listOfFiles[i].getName();
pp will store the relative path of files.
Now you will be able to list and download your file via hyperlink.
So I tried to make web page like application where user can view and download their files via web page. For that you require obviously Tomcat Server for running JSP pages.
So, you should have working knowledge of Tomcat Server.
Create a JSP page and save in your project directory and use this code.
<p><%
File folder = new File("G:\\tomcatserver\\webapps\\softshare\\share\\fonts");
File[] listOfFiles = folder.listFiles();
%><table><%
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String pp="share/fonts/"+listOfFiles[i].getName();
%><tr><td width="500px"><a href="<%=pp%>"><%=listOfFiles[i].getName()%></a><%
%></td><td><%
Path path=Paths.get(listOfFiles[i].getPath());
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
out.println(attr.creationTime().toString().substring(0,10));
out.println(" </td></tr>");
}
}
%></table><%
%></p>
Now lets see the code in details-
File folder = new File("G:\\tomcatserver\\webapps\\softshare\\share\\fonts"); //path of folder
File[] listOfFiles = folder.listFiles(); // will store file in array.
This code will read the files of fonts/ folder. The font folder should be in your project directory, it should not be out your tomcat server.
String pp="share/fonts/"+listOfFiles[i].getName();
pp will store the relative path of files.
Now you will be able to list and download your file via hyperlink.
No comments:
Post a Comment