Access to folders outside the application package (.ear / .war file)

Is there a way to make a folder that is NOT packaged into a war file accessible via GET.

Perhaps something was installed in web.xml?

+3
source share
2 answers

Yes, you can use the property alternatedocroot(in Glassfish) to serve files (like images) outside of the war.

This property can be a subelement of the sun-web-app element in the sun-web.xml file or the virtual server in the domain.xml file

See here: http://docs.sun.com/app/docs/doc/820-4496/geqpl?l=en&a=view

Example:

<property name="alternatedocroot_1" value="from=/images/* dir=/usr/gifs"/>
+4
source

You can add a servlet to the application that reads the file.

( )

public class FileDownloadServlet extends HttpServlet {

        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String filename = request.getParameter( "filename" );
        InputStream is;
        try {
            is = FileUtils.openInputStream( new File( filename ) );
            byte[] buf = new byte[ 8192 ];
            int bytesRead;
            while ( ( bytesRead = is.read( buf ) ) != -1 )
                os.write( buf, 0, bytesRead );
        }
        catch( ... ) {
        }
        finally {
            is.close();
            os.close();
        }
        response.setContentType( "application/octet-stream" );
      }
    }
+1

Source: https://habr.com/ru/post/1751553/


All Articles