tags:

views:

41

answers:

2

Hi gurus
I have problem with encode slash in url.

Problem:
from request in GSP page:
<a href="http://foo.cz/myapp/page/show?url=home/gallery"&gt;Gallery&lt;/a&gt;

I got:
http://foo.cz/myapp/page/show?url=home%2Fgallery
in address row in Internet browser.

Problem is with encode character from "/" to "%2F".

Explanation:
this is link in my gsp file:
<a href="http://foo.cz/myapp/page/show?url=home/gallery"&gt;Gallery&lt;/a&gt;

after click request goes to controller:

def show ={
    def page = Page.findByUrl( params.url ) //it works
}


then I got gsp page in my Internet browser. All work fine, I got required page, but in adress row in Internet browser I saw:
http://foo.cz/myapp/page/show?url=home%2Fgallery

There is not character "/", but encode "%2F"

Motivation
I want to set the url in UrlMapping.groovy to:

"/${url}" (controller:"page", action:"show")


and get:
http://foo.cz/myapp/home/gallery/
but there are problem with encode character "/".

Finish
Can you help me please?

Thanks a lot Tom

+2  A: 

you need to decode the Url in grails

http://www.grails.org/Dynamic+Encoding+Methods

Aaron Saunders
A: 

Hi gurus

it is not difficult replace "%2F" to "/", but then, there are problem with url mapping. Transformation is in Grails tag CreateLink.
See source. There are involve String method encodeAsURL() as Aaron Saunders told my above. For example, You can only write your own tag and use String method replaceAll("%F2", "/") and it work.

I got desired url in address row in Internet browser:
http://foo.cz/myapp/page/show?url=home/gallery

and I replaced to in MappingURL.groovy to:
http://foo.cz/myapp/home/gallery

Hmm, I have to use wildcart and other dirty code in controller. It is not nice code.

Now I know, that is not good idea use slash(/) in params as Olexandr told my above.

It is work fine when You use for example "-" or other save URL character as param delimiter.

Thanks a lot all gurus.

Tom

Tom