logo       

Re: URL Rewriting and Velocity: msg#00234

jakarta.velocity.user

Subject: Re: URL Rewriting and Velocity

What I do for Url rewriting directly in my templates is to add a handful of
helper macros to the VM_global_library.vm (see below) and then ensure I always
put the Servlet HttpResponse in the Velocity context under the name "response".

So when I need to rewrite an Url I just have to use the functions #Url,
#QuotedUrl, #Redirect and #QuotedRedirect - see the doc...

The VM_global_library.vm snippet:

##
## macro: Url
##
## parameters: $url
##
## description: Encodes a link with servlet session information
##
## prerequisite: Servlet response required to be placed in the
## context as 'response'.
##
## html use: <a href="#Url($link)">My link</a>
##
## July 2002, martin@xxxxxxxxxxxxxxxx
##
#macro( Url $url )
$response.encodeURL($url)#end

##
## macro: QuotedUrl
##
## parameters: $url
##
## description: Encodes a link with servlet session information and
## adds surrounding quotes.
##
## prerequisite: Servlet response required to be placed in the
## context as 'response'.
##
## html use: <a href=#Url($link)>My link</a>
##
## July 2002, martin@xxxxxxxxxxxxxxxx
##
#macro( QuotedUrl $url )
"$response.encodeURL($url)"#end

##
## macro: Redirect
##
## parameters: $url
##
## description: Encodes a redirect with servlet session information.
##
## prerequisite: Servlet response required to be placed in the
## context as 'response'.
##
## html use: <a href=#Url($link)>My link</a>
##
## July 2002, martin@xxxxxxxxxxxxxxxx
##
#macro( Redirect $url )
$response.encodeRedirectURL($url)#end

##
## macro: QuotedRedirect
##
## parameters: $url
##
## description: Encodes a redirect with servlet session information and
## adds surrounding quotes.
##
## prerequisite: Servlet response required to be placed in the
## context as 'response'.
##
## html use: <a href=#Url($link)>My link</a>
##
## July 2002, martin@xxxxxxxxxxxxxxxx
##
#macro( QuotedRedirect $url )
"$response.encodeRedirectURL($url)"#end



*********** REPLY SEPARATOR ***********

On 11/29/2002 at 18:29 Kwirirai wrote:

>Hi
>My question is does Velocity support URL Rewriting or I have to employ URL
>rewriting with my own
>Implementation. I know that with Servlets you can do URL Rewriting while
>printing out to the client. Since velocity
>Does the printing out ,how can URL Rewriting be done using velocity.
>
>kwiri
>
>
>--
>To unsubscribe, e-mail:
><mailto:velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx>
>For additional commands, e-mail: <mailto:velocity-user-help@xxxxxxxxxxxxxxxxxx>


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise