Results 1 to 4 of 4

Thread: Access request context path from velocity/freemarker

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    New York, NY
    Posts
    46

    Default Access request context path from velocity/freemarker

    I am trying to figure out how to make the context path of the current request available to the model for Velocity/Freemarker using SpringMVC. I need this to make absolute URLs work when needed. Is there a way to expose this easily to all my views?

    Thanks,
    Patrick

  2. #2
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    put the RequestContext into the model by setting the bean property 'requestContextAttribute' on your view (or view resolver for Velocity/FreeMarkerViewResolver). For example, in views.properties or equiv.
    Code:
    foo.requestContextAttribute=rc
    then in your template,
    Code:
    ${rc.contextPath}
    Regards,
    Darren Davison.
    Public Key: 0xE855B3EA

  3. #3
    Join Date
    Aug 2004
    Location
    New York, NY
    Posts
    46

    Default

    Thanks. I had seen that parameter before and had wondered if that was what I needed to set. Thanks for the clarification. I just tried it and like magic it worked.

    Patrick

  4. #4
    Join Date
    Oct 2009
    Posts
    3

    Thumbs up

    Append the jstl/core taglib in your freemarker file and set url as
    <@c.url value="<pathof css or js file>"/> @c.url automatic include contexpath.

    example:
    Code:
    <#assign c=JspTaglibs["http://java.sun.com/jsp/jstl/core"]/>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>	
    		<link type="text/css" rel="stylesheet" href="<@c.url value='/css/estilo.css'/>"/> 
    		<script type="text/javascript" src="<@c.url value='/js/jquery.js'/>"></script>
    </head>
    <body>
    .....
    </body>
    </html>

Similar Threads

  1. Replies: 11
    Last Post: Jun 1st, 2006, 04:30 PM
  2. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  3. Replies: 2
    Last Post: Oct 13th, 2005, 02:47 PM
  4. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

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