问题
I am trying to load an image into my jsp located in the 'files' folder on the class path.
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:
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
回答1:
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.
来源:https://stackoverflow.com/questions/26174776/load-image-in-jsp-from-different-url-but-same-domain