redirect from class to gsp page
I use grails and in service I have class in which before throw an exception开发者_运维问答 it have to redirect to gsp page.
Is there anyone who know how to redirect from class to gsp?
Thanks in advance.
Actually, redirect is designed to be used at the controllers, not services. Services should contain only the logic of your business, not the routing. Routing is the role of controllers. Moreover, if you throw an exception and then redirect, who will take the exception?
I think the better way is catching the exception thrown by the service at controller level, then do the redirecting.
You can view more abour redirect command here.
Simply use redirect(uri:'foo')
, which will redirect to foo.gsp
.
Update: you should not redirect from service. Services must be completely unaware of the web nature of the application. So, at most, redirection can depend on some return value by a service.
精彩评论