Search code examples
jakarta-eeweb-applicationsglassfishapplication-server

alternatedocroot not working on GlassFish 4.0


Here is my glassfish-web.xml

<glassfish-web-app>
    <property description="Uploaded Images" name="alternatedocroot_1" value="from=/uploads/* dir=C:\Uploads" />
</glassfish-web-app>

I have a photo fff.jpg in C:\uploads\

When i go to http://localhost:8080/MyWebApp/uploads/fff.jpg I get an HTTP Status 404 - Not Found error.

What might be wrong?


Solution

  • I guess the problem is that you specified the folder name you want to map to in the dir attribute.

    value="from=/uploads/* dir=C:\Uploads"
    

    This means that you want to access a folder named "uploads" in the path C:\Uploads.

    So actually when you access http://localhost:8080/MyWebApp/uploads/fff.jpg it tries to read from C:\Uploads\uploads\fff.jpg.

    Solutions:

    Change your glassfish-web.xml:

    value="from=/uploads/* dir=C:\"
    

    or create a new folder named "uploads" in C:\Uploads and put the pictures in that folder, so that they are really like C:\Uploads\uploads\fff.jpg.

    See also: