Results 1 to 2 of 2

Thread: Can't setup javascript and jquery

  1. #1
    Join Date
    Dec 2011
    Posts
    8

    Smile 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">
    hello();
    </script>


    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. #2
    Join Date
    Dec 2011
    Posts
    8

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •