public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        PrintWriter out;
        String  title = "Index of ";
        String dirName = (String)req.getAttribute("com.ibm.servlet.engine.webapp.dir.browsing.path");
        String reqURI = (String)req.getAttribute("com.ibm.servlet.engine.webapp.dir.browsing.uri");

        // PK81387 Start

        //I believe dirName is now the local dir, not the file system path
        File dir = null;
        URL dirURL = null;
        String dirNameFileSystemPath = req.getRealPath(dirName);
        //this is a servlet, we only have access to the ServletContextFacade
        ServletContext context = getServletConfig().getServletContext();   
        boolean fileSystem = false;
        //dirNameFileSystemPath!=null is not a good enough check to determine if you're in a container
        //if we have a container and there have been jsps compiled, it gives you the directory in the workarea
        if (dirNameFileSystemPath!=null) {
            fileSystem = true;
            dirName=dirNameFileSystemPath;
            dir = new File(dirNameFileSystemPath);

            // get path to war directory
            String contextRealPath = context.getRealPath("/");
            
            int idx=dirName.lastIndexOf(contextRealPath);
            
            if (idx!=-1) {
            	// subtract the war directory from teh reqiested directory
            	String matchString=dirName.substring(idx+contextRealPath.length());
            	
            	matchString=matchString.replace(File.separator,"/");
            	
            	// Ensure matchString starts with "/" so WSUtil.resolveURI processes leading "."s
            	if (!matchString.startsWith("/")) {
            	   matchString="/"+matchString;
            	}
            	
            	// remove a trailing "/" so tthat uriCaseCheck does a vlaid check.
            	if (matchString.endsWith("/")) {
            		matchString=matchString.substring(0, matchString.length()-1);
            	}
            	     
            	// checkWEB-INF unless esposeWebInfoOnDispatch is set and we are in a dispatched request
            	boolean checkWEBINF = !WCCustomProperties.EXPOSE_WEB_INF_ON_DISPATCH || (req.getAttribute(WebAppRequestDispatcher.DISPATCH_NESTED_ATTR)==null) ;
            	
            	try {
            		
            		if (!com.ibm.wsspi.webcontainer.util.FileSystem.uriCaseCheck(dir, matchString,checkWEBINF))
            		{
                        resp.sendError(404, nls.getString("File.not.found", "File not found"));
                        return;
            		}	
            	} catch (java.lang.IllegalArgumentException exc) {
            		// Must be traversing back directories
                    resp.sendError(404, nls.getString("File.not.found", "File not found"));
                    return;
            	}
             } else {
                 // Must be traversing back directories
                 //dirNameFileSystemPath was normalized in Liberty, whereas in tWAS it contained the root path followed by whatever was entered
                 resp.sendError(404, nls.getString("File.not.found", "File not found"));
                 return;
             }
        }
        else { //container
            dirURL = context.getResource(dirName);
            if (dirURL == null) {
                resp.sendError(404, nls.getString("File.not.found", "File not found"));
                return;
            }
        }
            // PK81387 End	
            if (!reqURI.endsWith("/"))
                reqURI += '/';
    
            title += reqURI;
    
            // make sure we can access it
            if (fileSystem && !dir.canRead())
                resp.sendError(404, nls.getString("File.not.found", "File not found"));
        // set the content type
		// set the content type as UTF-8 as filenames are encoded in UTF-8
        resp.setContentType("text/html; charset=UTF-8");

        // write the output
        out = resp.getWriter();

        out.println("<HTML><HEAD><TITLE>");
        out.println(title);
        out.println("</TITLE></HEAD><BODY>");
        out.println("<H1 align=\"left\">" + title + "</H1>");
        out.println("<HR size=\"3\"><TABLE cellpadding=\"2\"><TBODY><TR bgcolor=\"#d7ffff\">");

        // output the table headers
        out.println("<TH width=\"250\" nowrap><P align=\"left\">Name</P></TH>");
        out.println("<TH width=\"250\" nowrap><P align=\"left\">Last Modified</P></TH>");
        out.println("<TH width=\"150\" nowrap><P align=\"left\">Size</P></TH>");
        out.println("<TH width=\"300\" nowrap><P align=\"left\">Description</P></TH></TR>");

        // output a row for each file in the directory
        if (fileSystem) {
            fillTableRows(dir, reqURI, out);
        } else {
            fillTableRows(context, dirName, reqURI, out);
        }

        // finish the page
        out.println("</TBODY></TABLE></BODY></HTML>");

        // close it up
        out.close();
    }
public void doGet ( HttpServletRequest req , HttpServletResponse resp ) throws ServletException , IOException { PrintWriter out ; String title = "Index of " ; String dirName = ( String ) req . getAttribute ( "com.ibm.servlet.engine.webapp.dir.browsing.path" ) ; String reqURI = ( String ) req . getAttribute ( "com.ibm.servlet.engine.webapp.dir.browsing.uri" ) ; File dir = null ; URL dirURL = null ; String dirNameFileSystemPath = req . getRealPath ( dirName ) ; ServletContext context = getServletConfig ( ) . getServletContext ( ) ; boolean fileSystem = false ; if ( dirNameFileSystemPath != null ) { fileSystem = true ; dirName = dirNameFileSystemPath ; dir = new File ( dirNameFileSystemPath ) ; String contextRealPath = context . getRealPath ( "/" ) ; int idx = dirName . lastIndexOf ( contextRealPath ) ; if ( idx != - 1 ) { String matchString = dirName . substring ( idx + contextRealPath . length ( ) ) ; matchString = matchString . replace ( File . separator , "/" ) ; if ( ! matchString . startsWith ( "/" ) ) { matchString = "/" + matchString ; } if ( matchString . endsWith ( "/" ) ) { matchString = matchString . substring ( 0 , matchString . length ( ) - 1 ) ; } boolean checkWEBINF = ! WCCustomProperties . EXPOSE_WEB_INF_ON_DISPATCH || ( req . getAttribute ( WebAppRequestDispatcher . DISPATCH_NESTED_ATTR ) == null ) ; try { if ( ! com . ibm . wsspi . webcontainer . util . FileSystem . uriCaseCheck ( dir , matchString , checkWEBINF ) ) { resp . sendError ( 404 , nls . getString ( "File.not.found" , "File not found" ) ) ; return ; } } catch ( java . lang . IllegalArgumentException exc ) { resp . sendError ( 404 , nls . getString ( "File.not.found" , "File not found" ) ) ; return ; } } else { resp . sendError ( 404 , nls . getString ( "File.not.found" , "File not found" ) ) ; return ; } } else { dirURL = context . getResource ( dirName ) ; if ( dirURL == null ) { resp . sendError ( 404 , nls . getString ( "File.not.found" , "File not found" ) ) ; return ; } } if ( ! reqURI . endsWith ( "/" ) ) reqURI += '/' ; title += reqURI ; if ( fileSystem && ! dir . canRead ( ) ) resp . sendError ( 404 , nls . getString ( "File.not.found" , "File not found" ) ) ; resp . setContentType ( "text/html; charset=UTF-8" ) ; out = resp . getWriter ( ) ; out . println ( "<HTML><HEAD><TITLE>" ) ; out . println ( title ) ; out . println ( "</TITLE></HEAD><BODY>" ) ; out . println ( "<H1 align=\"left\">" + title + "</H1>" ) ; out . println ( "<HR size=\"3\"><TABLE cellpadding=\"2\"><TBODY><TR bgcolor=\"#d7ffff\">" ) ; out . println ( "<TH width=\"250\" nowrap><P align=\"left\">Name</P></TH>" ) ; out . println ( "<TH width=\"250\" nowrap><P align=\"left\">Last Modified</P></TH>" ) ; out . println ( "<TH width=\"150\" nowrap><P align=\"left\">Size</P></TH>" ) ; out . println ( "<TH width=\"300\" nowrap><P align=\"left\">Description</P></TH></TR>" ) ; if ( fileSystem ) { fillTableRows ( dir , reqURI , out ) ; } else { fillTableRows ( context , dirName , reqURI , out ) ; } out . println ( "</TBODY></TABLE></BODY></HTML>" ) ; out . close ( ) ; }
Handle the GET Method