Jaikrat
Jaikrat

Reputation: 1154

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>

Upvotes: 0

Views: 115

Answers (2)

JohnRose
JohnRose

Reputation: 409

c:url tag transfers url into a string format and assigns in a variable. It is an alternative method for response.encodeURL(). This tag automatically performs URL rewriting when necessary. It has some attribute. They are as follows var, value, context,scope.

Whereas for ordinary import browser has to do these things. It is time consuming

Advantage of rewriting URL;

It is browser independent.

Upvotes: 1

randomizer
randomizer

Reputation: 1649

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 (e.g. "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 (e.g. "/page2.jsp") so that such URLs can be properly interpreted by a client browser."

Upvotes: 1

Related Questions