简体   繁体   English

如何在JSP中导入.css和.js文件

[英]How to import .css and .js files in JSP

I know how to import, was not getting proper wording to ask this question. 我知道如何导入,没有得到正确的措辞来问这个问题。

So my question is, What is the difference between below two imports. 所以我的问题是,下面两个导入之间有什么区别。

<script type="text/javascript" src="resources/scripts/jquery/jquery-ui-1.8.19.custom.min.js" type="text/javascript"></script>

and

<script type="text/javascript" src="<c:url value='resources/scripts/jquery/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.min.js'/>"></script>

This is done so you can be sure the resources are referenced relative to the application context. 这样做是为了确保相对于应用程序上下文引用资源。 So you can be pretty sure if the file exists it will be found. 因此,您可以非常确定文件是否存在,它将被找到。

"The URL must be either an absolute URL starting with a scheme (eg "http:// server/context/page.jsp") or a relative URL as defined by JSP 1.2 in JSP.2.2.1 "Relative URL Specification". As a consequence, an implementation must prepend the context path to a URL that starts with a slash (eg "/page2.jsp") so that such URLs can be properly interpreted by a client browser." “URL必须是以方案开头的绝对URL(例如”http:// server / context / page.jsp“)或JSP.2.2.1”相对URL规范“中JSP 1.2定义的相对URL。因此,实现必须将上下文路径添加到以斜杠开头的URL(例如“/page2.jsp”),以便客户端浏览器可以正确解释这些URL。“

c:url tag transfers url into a string format and assigns in a variable. c:url标记将url转换为字符串格式并分配变量。 It is an alternative method for response.encodeURL(). 它是response.encodeURL()的另一种方法。 This tag automatically performs URL rewriting when necessary. 必要时,此标记会自动执行URL重写。 It has some attribute. 它有一些属性。 They are as follows var, value, context,scope. 它们如下var,value,context,scope。

Whereas for ordinary import browser has to do these things. 而普通导入浏览器必须要做这些事情。 It is time consuming 这很费时间

Advantage of rewriting URL; 重写URL的好处;

It is browser independent. 它独立于浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM