HTML or JSP page referencing the JS file in the jar package

Source: Internet
Author: User

One, the method of referencing the JS file in the jar package on the page

Using the Java web Framework appfuse found that the JS framework such as jquery, Bootstrap, and so on are encapsulated in the jar package. These JS files are compressed and integrated into a JS file by a wro4j tool. When using the page, refer to this JS file. By interpreting the process of WRO for JS processing, we find the method of HTML or JSP referencing the JS file in the jar package:

<C:setvar= "Base"value= "${pagecontext.request.contextpath}"/><Linkrel= "stylesheet"type= "Text/css"href= "${base}/webjars/bootstrap/3.3.1/css/bootstrap.min.css"/><Scripttype= "Text/javascript"src= "${base}/webjars/jquery.treegrid/0.3.0/js/jquery.treegrid.bootstrap3.js"></Script>

Note: If it is an HTML page, delete ${base} and <c:set var= "base" value= "${pagecontext.request.contextpath}"/>.

Where Bootstrap is located:

Jquery.treegrid's Location:

By comparison you can find the rule, the runtime system will mata-info/resources the following files into the system root directory.

Second, interpreting WRO for the compression integration of JS and CSS in the jar package and the page reference

First, the system introduces a jar package: Wro4j-core-1.7.5.jar.

The project code has a WRO configuration file:/src/main/webapp/web-inf/wro.xml, the contents of the file:

<?XML version= "1.0" encoding= "UTF-8"?><groupsxmlns= "Http://www.isdc.ro/wro">    <!--CSS URL rewriting fails when using Webjar resource locator:https://github.com/alexo/wro4j/issues/127 -    <Groupname= "Main">        <CSS>Classpath:meta-inf/resources/webjars/bootswatch-spacelab/3.3.1+2/css/bootstrap.min.css</CSS>        <CSS>/styles/style.css</CSS>        <JS>Classpath:meta-inf/resources/webjars/jquery/1.11.1/jquery.min.js</JS>        <JS>Classpath:meta-inf/resources/webjars/bootstrap/3.3.1/js/bootstrap.min.js</JS>        <JS>Classpath:meta-inf/resources/webjars/jquery-cookie/1.3.1/jquery.cookie.js</JS>        <JS>/scripts/script.js</JS>    </Group>    <Groupname= "Treegrid">        <CSS>Classpath:meta-inf/resources/webjars/bootstrap/3.3.1/css/bootstrap.min.css</CSS>        <CSS>Classpath:meta-inf/resources/webjars/jquery.treegrid/0.3.0/css/jquery.treegrid.css</CSS>        <JS>Classpath:meta-inf/resources/webjars/jquery.treegrid/0.3.0/js/jquery.treegrid.min.js</JS>        <JS>Classpath:meta-inf/resources/webjars/jquery.treegrid/0.3.0/js/jquery.treegrid.bootstrap3.js</JS>    </Group></groups>

Two group, the above main is the frame belt, the following treegrid is I added.

Parse label file:/src/main/webapp/web-inf/tags/assets.tag, the purpose of this file is to use XSLT to <t:assets group= "Treegrid" type= "JS" in the JSP file /> tags parsed into HTML tags: <script type= "Text/javascript" src= "/assets/v/92097/treegrid.js" ></script>

Another related file is the declaration of Assets.tag, a line in the/src/main/webapp/common/taglibs.jsp file: <%@ taglib prefix= "T" tagdir= "/web-inf/tags" %>

In series, explain it again.

1.wro.xml is the core configuration file, Wro4j-core-1.7.5.jar according to this configuration file to extract and compress the relevant JS file into a JS file.

2.taglibs.jsp in the Declaration of a label Assets.tag, this tag appears in the JSP file, the JSP tag itself into the HTML tag (point to the compressed single JS file), the page can be referenced.

In order to understand the HTML referenced in the jar package JS, the online collection of a lot of information, but not explained the more comprehensive. So write a blog to record, maybe can help the people who are suffering.

HTML or JSP page referencing the JS file in the jar package

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.