You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Kwirirai <kw...@ibsdev.africaonline.co.zw> on 2002/11/29 17:29:44 UTC

URL Rewriting and Velocity

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
 

Re: URL Rewriting and Velocity

Posted by "technosf@speakeasy.net" <te...@speakeasy.net>.
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@technomation.net
##
#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@technomation.net
##
#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@technomation.net
##
#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@technomation.net
##
#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:  
><ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: URL Rewriting and Velocity

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On Friday, November 29, 2002, at 11:29 AM, 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.
>

Velocity itself doesn't know anything about URL rewriting, as it isn't 
specifically for the web environment.  You can add tools or data to 
your context to help with this, though - people do it all the time.

Another thing you might consider is looking at the web application 
frameworks that work with velocity.  See

    http://jakarta.apache.org/velocity/powered.html

for a list

-- 
Geir Magnusson Jr                                   203-355-2219(w)
Adeptra, Inc.                                       203-247-1713(m)
geirm@adeptra.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>