reset password
Author Message
dguhath
Posts: 61
Posted 01:32 Feb 20, 2015 |

Hello Dr. Sun,

I am facing some issues in using jquery in my jsp files. I guess the file path is not getting resolved properly. Is there some configuration required to get it to work?

I tried using <mvc:resources mapping="/javascript/**" location="/javascript/" /> in the dispatcher-servlet.xml file & <script type="text/javascript" src="<c:url value="/javascript/jquery-2.1.1.min.js" />"></script> in the jsp file. Should this work?

Thanks.

cysun
Posts: 2935
Posted 08:31 Feb 20, 2015 |

If your DispatcherServlet is mapped to *.html, you don't need the <mvc:resources> as the application server will serve any static resources that are not mapped to the DispatcherServlet. Just put the /javascript folder under /webapp and it should work.

dguhath
Posts: 61
Posted 09:02 Feb 20, 2015 |

Thanks Dr Sun.

I tried putting in the <mvc:resource> as it was not working but that was also not useful.

My DispatcherServlet is mapped to *.html & my /javascript folder is under /webapp. 

The script code i am writing is not getting color coded. I guess that's an indication of the linking not happening?

cysun
Posts: 2935
Posted 09:04 Feb 20, 2015 |
dguhath wrote:

Thanks Dr Sun.

I tried putting in the <mvc:resource> as it was not working but that was also not useful.

My DispatcherServlet is mapped to *.html & my /javascript folder is under /webapp. 

The script code i am writing is not getting color coded. I guess that's an indication of the linking not happening?

Try the URL of the script directly, e.g. http://localhost:8080/gefp/javascript/jquery...

If you can see the script, it means it's not a linking problem.

dguhath
Posts: 61
Posted 09:35 Feb 20, 2015 |

Hello Dr. Sun,

I tried a couple of solutions and both worked.

I tried the whole link http://localhost:8080/gefp/javascript/ as you suggested. I also tried "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"

I read a post saying it's good to use one of the widely available servers as if the user has already downloaded the file they don't need to redo it. Do you think that is accurate?

Thanks.

cysun
Posts: 2935
Posted 14:48 Feb 20, 2015 |

Actually my suggestion was to enter the URL in the browser and see if you could access the js file directly - it was intended to determine whether it's a URL problem in the first place, not a suggested fix to the problem.

In a production system it's recommended to link to a copy of the library hosted on a CDN for the reason you mentioned. During development you may want to use a local copy so you don't have to have an internet connection all the time.

dguhath
Posts: 61
Posted 15:34 Feb 20, 2015 |

Oh ok. I'll try to see why it is not working then.

Thanks Dr.Sun