IntelliJ Java IDE
The moose likes Spring and the fly likes Javascript and the DispatcherServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "Javascript and the DispatcherServlet" Watch "Javascript and the DispatcherServlet" New topic
Author

Javascript and the DispatcherServlet

John Eric Hamacher
Ranch Hand

Joined: Apr 25, 2007
Posts: 223
Hello:

My external javascript files are not being recognized in Spring MVC. For example I have:

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

in my JSP. My javascript files are in a directory called "js" which is immediately inside the context root. Therefore, you would think:

<mvc:resources mapping="/js/**" location="/js/"/>

in the context file would take care of this but it doesn't. I have tried all kinds of variations in the <script> tag and the <mvc:resources> tag to no avail.

I'm looking for ideas because I'm stumped.

Thanks
Eric
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

Your URLs should all start with the context path.

Programatically, it can be obtained via ${pageContext.request.contextPath}


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
John Eric Hamacher
Ranch Hand

Joined: Apr 25, 2007
Posts: 223
Already tried that.
John Eric Hamacher
Ranch Hand

Joined: Apr 25, 2007
Posts: 223
Ok its working, I guess I didn't try putting in the context root with the current <mvc:resources> I tried.


thanks!
 
IntelliJ Java IDE
 
subject: Javascript and the DispatcherServlet
 
Threads others viewed
Prototype Ajax.Request error - Function Expected Options
Thought I knew WAR structure: Spring MVC/JQuery (simple) path problem
javascript include src path not right
Including .js files into certain pages
problem with webapp directory structure
developer file tools