Last active
October 2, 2018 04:57
-
-
Save authentical/d85c42389080082983b87d105f645db7 to your computer and use it in GitHub Desktop.
This JSP helps me view the folders and files in the WebContent directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@page import="java.util.Arrays"%> | |
<%@page import="java.io.File"%> | |
<%@page import="java.util.ArrayList" %> | |
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" | |
pageEncoding="ISO-8859-1"%> | |
<% | |
File jsp = new File(request.getSession().getServletContext().getRealPath(request.getServletPath())); | |
File[] directoryListArray = jsp.getParentFile().listFiles(); | |
ArrayList<File> directoryList = new ArrayList<>(); | |
directoryList.addAll(Arrays.asList(directoryListArray)); | |
%> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="ISO-8859-1"> | |
<title>Index of WebContent</title> | |
</head> | |
<body> | |
<h1>Index of WebContent</h1> | |
<table> | |
<tbody> | |
<tr><th valign="top"><th>Name</th></tr> | |
<tr><th colspan="5"><hr></th> | |
<% | |
StringBuilder index= new StringBuilder(); | |
for(File entry: directoryList){ | |
int lastSlashIndex = entry.toString().lastIndexOf('\\'); | |
index.append("<tr><td valign=\"top\"></td>"); | |
index.append("<td>" + | |
entry.toString().substring(lastSlashIndex, entry.toString().length()) + | |
" </td>"); | |
index.append("</td><td> </td></tr>"); | |
out.write(index.toString()); | |
index.setLength(0); | |
} | |
%> | |
<tr><th colspan="5"><hr></th> | |
</tbody> | |
</table> | |
<address>Java EE at localhost Port 8080</address> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This WebContent directory view is a bit messy right now. Pretty sure I can use Spring functionality to make this cleaner.. but right now its just a plain Dynamic Web Project.