The html or jsp page references the js file in the jar package,

Source: Internet
Author: User

The html or jsp page references the js file in the jar package,

I. How to reference the js file in the jar package on the page

When using the java web framework AppFuse, we found that js frameworks such as jquery and bootstrap are encapsulated in jar packages. These js files are compressed and integrated into a js file using a wro4j tool. When using the page, you can reference this js file. By interpreting wro's js processing process, we found the method for referencing js files in the jar package in html or jsp:

<c:set var="base" value="${pageContext.request.contextPath}"/><link rel="stylesheet" type="text/css" href="${base}/webjars/bootstrap/3.3.1/css/bootstrap.min.css"/><script type="text/javascript" src="${base}/webjars/jquery.treegrid/0.3.0/js/jquery.treegrid.bootstrap3.js"></script>

Note: For an html page, delete $ {base} and <c: set var = "base" value = "$ {pageContext. request. contextPath}"/>.

The bootstrap location:

 

Location of jquery. treegrid:

Through the comparison, we can find that the system will extract the files under the MATA-INFO/resources to the system root directory at runtime.

 

Ii. Interpretation of wro's JavaScript and css compression integration and page reference in the jar package

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

The project code contains a wro configuration file:/src/main/webapp/WEB-INF/wro. xml, the content of this file:

<?xml version="1.0" encoding="UTF-8"?><groups xmlns="http://www.isdc.ro/wro">    <!-- CSS URL Rewriting fails when using webjar resource locator:         https://github.com/alexo/wro4j/issues/127 -->    <group name="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>    <group name="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 groups. The above main is brought by the framework, and the following treegrid is added by me.

Tag file for parsing tags:/src/main/webapp/WEB-INF/tags/assets. tag. The purpose of this file is to use xslt to parse the <t: assets group = "treegrid" type = "js"/> tag in the jsp file into an html tag: <script type = "text/javascript" src = "/assets/v/92097/treegrid. js "> </script>

Another related file is for assets. tag declaration,/src/main/webapp/common/taglibs. A line in the jsp file: <% @ taglib prefix = "t" tagdir = "/WEB-INF/tags" %>

Concatenate and explain it again:

1. wro. xml is the core configuration file, the wro4j-core-1.7.5.jar according to this configuration file extraction and compression of relevant js files into a js file.

2. taglibs. A tag assets is defined in jsp. tag. When this tag appears in a jsp file, the jsp tag parses itself into an html tag (pointing to a single compressed js file), and the page can be referenced.

I have collected a lot of information on the Internet to learn about js referenced in the jar package in html, but I have not explained it comprehensively. So write a blog to record it, maybe it can help people who are in distress.

 

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.