Grails way to prevent bad request "ids" on url
Like here in stackoverflow if i force put bad characters on URL in id place it redirects you to a page error. I would like to know if with Grails it has some kind of plugin for prevent id like: "123$#3" or an easy way because i have a lot of actions and do something like below dont seems to be the best way:
def find = {
def val = OwnStringUtilsClass.verify(params.id)
val ? Book.get(val) : response.sendErr开发者_StackOverflow社区or(404)
}
You can use the following in grails-app/conf/UrlMappings.groovy
:
"/$controller/$action?/$id?"{
constraints {
id(matches:/\d*/)
}
}
This will ensure that the id
is numeric.
You could try using a controller filter.
精彩评论