Results 1 to 4 of 4

Thread: JavaScript will only load if located in /static

  1. #1
    Join Date
    Jan 2012
    Posts
    16

    Default JavaScript will only load if located in /static

    Hi,

    I'm coming across a problem when using Spring Security with JavaScript or CSS files.

    I have a project I am building with Maven and have the following structure:

    /static
    /jsapp
    /login.jsp
    /index.jsp

    I use the standard login from spring security and that works fine. The problem occurs when index.jsp loads and pulls in a JS file from the /jsapp folder. The file appears to have the content of the index.jsp instead of it's actual content.

    Now, if I move the /jsapp to sit under /static, it works perfectly!

    Is there a requirement for all JS files (and similar) to sit under the /static folder? If so, is there a way around this? Can I store JS files in a folder which is not the /static one?

    Thanks,
    Ale

  2. #2
    Join Date
    Dec 2008
    Location
    India
    Posts
    295

    Default

    you can place js/css to any folder, just make sure that its filter="none" is there.
    Enjoy
    Rohan Chauhan
    ------------------------------------------------------------------------------
    SpringSource Certified Spring 3.0 Professional


  3. #3
    Join Date
    Jan 2012
    Posts
    16

    Default

    Hi Rohan, thanks for the response. Setting filters to none is essentially the same as setting security to none in the <http> tag.

    I'd like to maintain the files in jsapp with security.

    To maintain security, the folder needs to be under static or it won't server the JS correctly.

    On a side note, filters is deprecated with version 3.1

  4. #4
    Join Date
    Jan 2012
    Posts
    16

    Default

    Found out how to fix this issue. I added the following to the web.xml:

    Code:
    	<servlet-mapping>
    		<servlet-name>default</servlet-name>
    		<url-pattern>/static/*</url-pattern>
    		<url-pattern>/myfolder/*</url-pattern>
    		<url-pattern>/myotherfolder/*</url-pattern>
    	</servlet-mapping>

Posting Permissions

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