Results 1 to 5 of 5

Thread: Static content problem

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    3

    Default Static content problem

    Hi gurus,
    I'm completely new to web technologies and try to write my first Spring MVC application. I have following problem:
    My project has following structure:
    - WEB-iNF
    classes - compuled java code (controllers etc.)
    views - jsp pages
    lib - Spring and other libraries
    css - folder with my css files
    I use <mvc:resources> in following way:
    Code:
    <mvc:resources mapping="/resources/**" location="/css/" cache-period="31556926" />
    My understanding here is that I "map" /resources to /css directory.
    I run my application using Glassfish server (ver. 3.1.2) and see in the log following enrty:
    Code:
    Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
    It seems to be OK. Next I'll try to use my css file within jsp using:
    Code:
    <link rel="stylesheet" href="<s:url value="/resources/main.css" />" type="text/css">
    where s points to :
    Code:
    <%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
    And this doesn't work without any information. I'll try to get access to main.css file directly from the browser but always get HTTP Status 404 - The requested resource is not available. Any help will be very appreciated.

  2. #2
    Join Date
    Mar 2007
    Posts
    128

    Default

    Your css directory should go under /src/main/webapp/resources, not web-inf (assuming you're using a maven project directory format).

  3. #3
    Join Date
    Nov 2012
    Posts
    3

    Default

    Hi,
    You're right I have MAVEN project nad move folder as you mentioned but it doesn't help
    I suspect that something is wrong with jsp page. when I look at page source (from browser side) following code is displayed:
    Code:
     <link rel="stylesheet" href="/RPC/resources/main.css" type="text/css">
    My jsp file looks like
    Code:
    <link rel="stylesheet" href="<s:url value="/resources/main.css" />" type="text/css">
    It seems that phrase /resources/main.css is not mapped to /css/main.css as I expect.

  4. #4
    Join Date
    Mar 2007
    Posts
    128

    Default

    Did you move the whole css directory under resources? If so your url would be "<s:url value="/resources/css/main.css"

  5. #5
    Join Date
    Nov 2012
    Posts
    3

    Default

    Yes I move whole css directory. I change s:url tag but without success. I thought that mvc:resources tag mapps all static content to /css directory directly.

Posting Permissions

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