javajspstruts2static-contentimageurl

Load image in jsp from different URL but same domain?


I am trying to load an image into my jsp located in the 'files' folder on the class path.

enter image description here

The URL of the .jsp in which I try to load images is http://www.my-webapp.com/authenticated/dashboard. The problem is that jsp is searching for the 'files' folder inside the 'authenticated' folder instead of class path.

This is the URL I get when I use the 'Inspect Element' of Google Chrome:

enter image description here

How can I tell my jsp to search for 'files folder on classpath but not in 'authenticated' folder?

My struts.xml (if needed):

<package name="account" namespace="/authenticated" extends="struts-default">

    <action name="dashboard" class="DashLoader" method="execute">
        <result name="success">/authenticated/dashboard.jsp</result>
    </action>

</package>

Thank you


Solution

  • The default content loader allows you to serve static content from the classpath. This loader handles URLs that start with /static. So, if you put your image on the classpath under the files package, then it could be accessed like /static/files/image.jpg.

    You can read more about static content loader and configuration settings in the docs for Static Content.