Announcement Announcement Module
Collapse
No announcement yet.
Is that reason file can't get loaded? Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is that reason file can't get loaded?

    In my JSP file, I have the following

    Code:
    <script type="text/javascript" src="/vsm/static/js/jquery-1.3.2.min.js"></script>
    the above code is shown after the JSP file is processed.

    The jQuery library can't get loaded for some reason. The file physical path is correct to my eyes as:

    c:\Program Files\Apache Software Foundation\tomcat 6.0\webapps\vsm\static\js\*.*
    The application name is missing from the URL shown in the log messages below:
    2009-11-26 11:14:20,703 DEBUG [org.springframework.security.web.FilterChainProxy] - Converted URL to lowercase, from: '/static/js/jquery-1.3.2.min.js'; to: '/static/js/jquery-1.3.2.min.js'
    2009-11-26 11:14:20,703 DEBUG [org.springframework.security.web.FilterChainProxy] - Candidate is: '/static/js/jquery-1.3.2.min.js'; pattern is /static/**; matched=true
    2009-11-26 11:14:20,703 DEBUG [org.springframework.security.web.FilterChainProxy] - has an empty filter list
    Is the reason the Javascript file can't get loaded?

  • #2
    No. The paths are context-relative.

    How do you know the file isn't getting loaded? Do you get a 404 response?

    Comment


    • #3
      Originally posted by Luke Taylor View Post
      No. The paths are context-relative.

      How do you know the file isn't getting loaded? Do you get a 404 response?
      Thanks Luke.

      Yes, when I click a url of one those files on the HTML source file, I get the 404.
      Last edited by vw729; Nov 27th, 2009, 04:16 PM.

      Comment


      • #4
        When I point to a directory right under the Tomcat application installation http://localhost/vsm/static/, I get the 404 error. I can't think of any other factors other than Spring security.

        Comment


        • #5
          Another screen shoot.

          Comment


          • #6
            Hi

            Can you send your Spring-Security configuration and corresponding web.xml mapping?

            Usually Spring-Security's filter has mapping "/*" in web.xml - this is OK, but you usually don't want to use the same mapping for one of your DispatcherServlets.

            regards
            Grzegorz Grzybek

            Comment


            • #7
              Originally posted by Grzegorz Grzybek View Post
              Hi

              Can you send your Spring-Security configuration and corresponding web.xml mapping?

              Usually Spring-Security's filter has mapping "/*" in web.xml - this is OK, but you usually don't want to use the same mapping for one of your DispatcherServlets.

              regards
              Grzegorz Grzybek
              Here is the web.xml
              Code:
              <?xml version="1.0" encoding="ISO-8859-1"?>
              <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
              	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
              
              	<display-name>My App</display-name>
              
              	<description>...</description>
              
              	<context-param>
              		<param-name>webAppRootKey</param-name>
              		<param-value>vsm.root</param-value>
              	</context-param>
              
              	<context-param>
              		<param-name>log4jConfigLocation</param-name>
              		<param-value>/WEB-INF/classes/log4j.properties</param-value>
              	</context-param>
              
              	<context-param>
              		<param-name>contextConfigLocation</param-name>
              
              		<param-value>
              			/WEB-INF/applicationContext.xml
              			/WEB-INF/applicationContext-hibernate.xml
              			/WEB-INF/applicationContext-security.xml
              		</param-value>
              
              	</context-param>
              
              	<listener>
              		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
              	</listener>
              	
              	<!--
              		- Map static resources to the default servlet 
              	-->
              	<servlet-mapping>
              		<servlet-name>default</servlet-name>
              		<url-pattern>/static/*</url-pattern>
              	</servlet-mapping>
              
              	<servlet>
              		<servlet-name>vsm</servlet-name>
              		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
              		<load-on-startup>2</load-on-startup>
              	</servlet>
              
              	<!--
              		- Maps the petclinic dispatcher to "*.do". All handler mappings in -
              		petclinic-servlet.xml will by default be applied to this subpath. - If
              		a mapping isn't a /* subpath, the handler mappings are considered -
              		relative to the web app root. - - NOTE: A single dispatcher can be
              		mapped to multiple paths, like any servlet.
              	-->
              	<servlet-mapping>
              		<servlet-name>vsm</servlet-name>
              		<url-pattern>/</url-pattern>
              	</servlet-mapping>
              
              	<filter>
              		<filter-name>httpMethodFilter</filter-name>
              		<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
              	</filter>
              
              	<filter>
              		<filter-name>springSecurityFilterChain</filter-name>
              		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
              	</filter>
              
              	<filter-mapping>
              		<filter-name>httpMethodFilter</filter-name>
              		<servlet-name>vsm</servlet-name>
              	</filter-mapping>
              	
               	<filter>
              		<filter-name>encodingFilter</filter-name>
              		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
              		<init-param>
              			<param-name>encoding</param-name>
              			<param-value>UTF-8</param-value>
              		</init-param>
              		<init-param>
                          <param-name>forceEncoding</param-name>
                          <param-value>true</param-value>
                      </init-param>
              	</filter>
              
              	<filter-mapping>
              		<filter-name>encodingFilter</filter-name>
              		<url-pattern>/*</url-pattern>
              	</filter-mapping>	
              	
              
              	<filter-mapping>
              		<filter-name>springSecurityFilterChain</filter-name>
              		<url-pattern>/*</url-pattern>
              	</filter-mapping>
              
              	<session-config>
              		<session-timeout>10</session-timeout>
              	</session-config>
              
              	<error-page>
              		<exception-type>java.lang.Exception</exception-type>
              		<!-- Displays a stack trace -->
              		<location>/WEB-INF/jsp/uncaughtException.jsp</location>
              	</error-page>
              	<!--
              		<error-page> <error-code>404</error-code>
              		<location>pageNotFound</location> </error-page>
              	-->
              </web-app>
              and
              Code:
              <?xml version="1.0" encoding="UTF-8"?>
              
              <beans:beans xmlns="http://www.springframework.org/schema/security"
              	xmlns:beans="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
              	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              	xsi:schemaLocation="http://www.springframework.org/schema/beans 		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
              						http://www.springframework.org/schema/security		http://www.springframework.org/schema/security/spring-security-3.0.xsd">
              
              	<!-- For hashing and salting user passwords -->
              	<beans:bean id="passwordEncoder"
              		class="org.springframework.security.authentication.encoding.ShaPasswordEncoder" />
              	<beans:bean id="saltSource"
              		class="org.springframework.security.authentication.dao.ReflectionSaltSource"
              		p:userPropertyToUse="id" />
              
              	<http auto-config="true" access-denied-page="/accessDenied">
              		<intercept-url pattern="/static/**" filters="none" />
              	<!--  	<intercept-url pattern="/site/admin/**" access="ROLE_ADMIN" /> -->
              		<intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
              		<form-login login-page='/login' default-target-url="/"/>
              	</http>
              	<authentication-manager>
              		<authentication-provider>
              			<jdbc-user-service data-source-ref="dataSource"
              				authorities-by-username-query="select u.username, r.role from vsm_profile u left join vsm_role r on (u.id=r.user_fk) where u.username=?"/>
              		</authentication-provider>
              	</authentication-manager>
              
              </beans:beans>

              Comment


              • #8
                Hi

                It's intrigued me so much, that I had to check it
                You've "got out of your application" by mapping "/static/*" to Tomcat's default servlet. And Tomcat just ... removes the "static/" part from your request path, so:
                use src="/vsm/static/static/js/jquery-1.3.2.min.js"
                or
                move everything from c:\Program Files\Apache Software Foundation\tomcat 6.0\webapps\vsm\static\ up to c:\Program Files\Apache Software Foundation\tomcat 6.0\webapps\vsm\

                that's it!

                regards
                Grzegorz Grzybek

                Comment


                • #9
                  Originally posted by Grzegorz Grzybek View Post
                  Hi

                  It's intrigued me so much, that I had to check it
                  You've "got out of your application" by mapping "/static/*" to Tomcat's default servlet. And Tomcat just ... removes the "static/" part from your request path, so:
                  use src="/vsm/static/static/js/jquery-1.3.2.min.js"
                  or
                  move everything from c:\Program Files\Apache Software Foundation\tomcat 6.0\webapps\vsm\static\ up to c:\Program Files\Apache Software Foundation\tomcat 6.0\webapps\vsm\

                  that's it!

                  regards
                  Grzegorz Grzybek
                  Thanks for your input. However, I am not sure about your suggestion. It is a REST application.
                  The directory layout is based on a Spring sample. The reason of the 404 error on directory path http://localhost/vsm/static/, I believe, is that the REST system views it as a URL. And there isn't a such URL defined in the application. I am still not clue on the CSS and javascript file problem.
                  Last edited by vw729; Dec 17th, 2009, 07:00 PM.

                  Comment


                  • #10
                    Hi

                    The REST style of application doesn't have anything with the fact you're delegating to Tomcat's (specific) "default" servlet. Just remove the mapping to "default" servlet from your web.xml and everything will be fine.

                    Or look at the solution Spring-WebFlow (JS subproject) provides in the scope of resource provision (org.springframework.js.resource.ResourceServlet).

                    regards
                    Grzegorz Grzybek

                    Comment


                    • #11
                      Originally posted by Grzegorz Grzybek View Post
                      Hi

                      The REST style of application doesn't have anything with the fact you're delegating to Tomcat's (specific) "default" servlet. Just remove the mapping to "default" servlet from your web.xml and everything will be fine.

                      Or look at the solution Spring-WebFlow (JS subproject) provides in the scope of resource provision (org.springframework.js.resource.ResourceServlet).

                      regards
                      Grzegorz Grzybek
                      What make you said so? As I had mentioned, the purpose of the configuration is for REST to exclude some paths. Otherwise, I get something like
                      No mapping found for HTTP request with URI [/vsm/static/css/form.css] in DispatcherServlet with name ...

                      Comment


                      • #12
                        Hi

                        You get "No mapping found" error because the URL is mapped to your (single) DispatcherServlet. I can't figure out why, because your web.xml maps "/" to vsm servlet, and not "/*".

                        Generally it is not a good idea to map some URLs to Tomcat's specific servlet. Add another servlet mapping to "vsm" servlet with path "/rest/*" or something and get rid of "/static/*" mapping".

                        Standard Java EE servlets mapping are poor - there are only 3 kinds of mapping - "*.ext", "/path" or "/path/*". When you want some base path to be excluded from more general mapping, it's not that easy.
                        You may serve static resources from "/static/*" base path by mapping "application" requests by extension (e.g. *.do) or by <b>other</b> base path (e.g. "/app" or "/main", or something).

                        regards
                        Grzegorz Grzybek

                        Comment

                        Working...
                        X