We are currently using the struts2-jquery plugin in our web-application. The plugin works great but I have some questions about the internal workings of a struts2 plugin.
We added the plugin to the classpath and can use the tags defined in the taglib. When I look in the source code of the generated page I can see that the recourse are correctly included:
<script type="text/javascript" src="/struts/js/base/jquery-1.x.x.min.js"></script>
<script type="text/javascript" src="/struts/js/base/jquery-ui.min.js"></script>
...
The first question is: how does our web-application know that /struts/ points to the jquery plugin. We did not define anything for that.
The seems to come from the DefaultStaticContentLoader class. There is a method like this:
public boolean canHandle(String resourcePath) {
return serveStatic && (resourcePath.startsWith("/struts/") || resourcePath.startsWith("/static/"));
}
The second question is that when we call an url like /struts/ or /struts/themes/ the application downloads a file from the plugin as an octet stream (The final result seems to be a zip files containing the css, js and image files). Why is it doing that and is there a way to prevent that.
The second question is more important than the first.
Thanks, Tom.
EDIT: Question one was answered.
Well Plugin is was provided by the S2 to extends its functionality and change the way S2 work in certain use-case.
Struts 2 plugins contain classes and configuration that extend, replace, or add to existing Struts framework functionality.Plugin should contains struts-plugin.xml file to tell S2 which is the entry point for the plugin.
So when S2 start-up, it loads the configuration in a specific manner and sequence.
So struts-plugin.xml being part of the plugin (jar) will be loaded by the S2 and will register with itself its presence.
for more details refer to the official documents
A typical entry in struts-plugin.xml file for JQuery plugin is
Which tells S2 that
JqueryTagLibraryis the entry point for plugin.The one mentioned by you about loading static content is default S2 handling mechanism until we do no provide any standard mechanism.Struts provides a default implementation of StaticContentLoader which is
org.apache.struts2.dispatcher.DefaultStaticContentLoader. This loader will handle urls that start with “/static/“.For details how the static content being served by S2 from plugin and from it score jars refer to the doc