Announcement Announcement Module
No announcement yet.
Can't setup javascript and jquery Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't setup javascript and jquery

    Hi guys, I'm having problems setting up javascript and jquery in my maven spring mvc project.

    This is what I have done so far.

    1) Under webapp, I created a js folder. Inside I put a jquery.js and a myscript.js

    In one of my jsp pages, I'm trying to a call a function inside myscript.js, but it doesn't work. I tried many different paths, but still the problems persists.

    Inside myscript.js there is a function called hello for testing purposes.

    function hello()
    alert("Hello world");

    Inside addUser.jsp there is a declaration

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

    And a call to a method..

    <script type="text/javascript">

    It doesn't call the function. If i put the hello function inside the jsp, it works, but I don't want it in the same file.

    Any ideas guys?

  • #2
    Solved it. Anyone else that has problems this is what I did.

    Under spring.xml, which is probably your: projectname-servlet.xml

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

    Create a folder named js under webapp, but not in the WEB-INF directory.
    Put your .js files in there

    access your js files via.....

    <script type="text/javascript" src="<c:url value='/js/jquery.js' />"></script>
    <script type="text/javascript" src="<c:url value='/js/myscript.js' />"></script>

    Bon Voyage and happy new year.