0

in asp.net, actually we can use ~/jquery.js means that jquery.js is in the root folder. but how do we know what is root for jsp?

actually /jquery.js didnot work, suppose we run our app in http://mypcname.com:8084/131X/ the ~/jquery.js in asp.net goes to http://mypcname.com:8084/131X/jquery.js but the /jquery.js will go to http://mypcname.com:8084/jqeury.js

4 Answers4

1

Use this to include the JS file.

<script src="${pageContext.request.contextPath}/jquery.js"></script>

You can get a detailed answer here.

Community
  • 1
  • 1
AllTooSir
  • 48,828
  • 16
  • 130
  • 164
1

With JSTL it will be

<script src="<c:url value="/path/jquery.js"/>"></script>
Alex
  • 11,451
  • 6
  • 37
  • 52
1

you may use the following code,

<script type="text/javascript" src="<%=request.getContextPath()%>/jquery.js">
</script>

This code :-

<script src="${pageContext.request.contextPath}/jquery.js"> 

will do the same thing.

it would take you to the base url of the application http://mypcname.com:8084/

hence http://mypcname.com:8084/jquery.js would load your javascript file.

You will need to insert your javascript file to webapp folder

0

It has to start with a slash as follows :

<script type="text/javascript" src="/jquery.js"></script>

It will refer jquery.js from the root folder.

Visruth
  • 3,430
  • 35
  • 48