Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Is that reason file can't get loaded?

  1. #1

    Default 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?
    [URL="http://vicina.info"] 新闻,社区新闻,分类广告

  2. #2
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    No. The paths are context-relative.

    How do you know the file isn't getting loaded? Do you get a 404 response?
    Spring - by Pivotal
    twitter @tekul

  3. #3

    Default

    Quote 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 at 04:16 PM.
    [URL="http://vicina.info"] 新闻,社区新闻,分类广告

  4. #4

    Default

    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.
    Attached Images Attached Images
    [URL="http://vicina.info"] 新闻,社区新闻,分类广告

  5. #5

    Default

    Another screen shoot.
    Attached Images Attached Images
    [URL="http://vicina.info"] 新闻,社区新闻,分类广告

  6. #6
    Join Date
    Oct 2008
    Location
    Poland, Wrocław
    Posts
    427

    Default

    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

  7. #7

    Default

    Quote 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>
    [URL="http://vicina.info"] 新闻,社区新闻,分类广告

  8. #8
    Join Date
    Oct 2008
    Location
    Poland, Wrocław
    Posts
    427

    Default

    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

  9. #9

    Default

    Quote 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 at 07:00 PM.
    [URL="http://vicina.info"] 新闻,社区新闻,分类广告

  10. #10
    Join Date
    Oct 2008
    Location
    Poland, Wrocław
    Posts
    427

    Default

    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

Posting Permissions

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