How struts 2 include javascript files in jsp from their struts.jar?

I noticed that the client-side validation function based on the struts 2 platform javascript uses the javascript file, which is included in the struts2 JAR file. The javascript file is somehow included in the JSP page, just using the tag from the framework.

If I manage to do this, it will be extremely useful for many javascript library files that I always copy in every new web project, because I put them all in a JAR file, and then each project will not have a different copy of the files (which, as you know, cause a lot of problems).

Does anyone know how they did this?

+3
source share
2 answers

, , . , Struts 2 . struts.properties : struts.serve.static.

true (javascript, css, images ..) JSP, /struts/ /static/ struts FilterDispatcher , DefaultStaticContentLoader.

:

<script language="JavaScript" type="text/javascript" src="struts/someScript.js"></script>
<script language="JavaScript" type="text/javascript" src="static/otherScript.js"></script>

javascript ContentLoader.

ContentLoader JAR Struts 2: org.apache.struts2.static .

ContentLoader , web.xml , :

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
    <param-name>packages</param-name>
    <param-value>insert.your.package.with.static.content.here</param-value>
</init-param>
</filter>

, , . API Struts2 FilterDispacher , : " ".

, , , .

+9
-1

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


All Articles