开发者

How to handle correctly a URL having twice the same parameters with same values?

开发者 https://www.devze.com 2023-01-15 04:47 出处:网络
Using Grails 1.3.3, when requesting url link: /myapp/mycontroller/myaction?p1=v1&p2=v2&p1=v1 then params injected value into Grails controller will contain :

Using Grails 1.3.3, when requesting url link:

/myapp/mycontroller/myaction?p1=v1&p2=v2&p1=v1

then params injected value into Grails controller will contain :

assert params.p1== ['v1','v1']

It would have been logical to me that params.p1 equals to 'v1', no?

In any case, is there any way to c开发者_如何学JAVAhange this behavior?

Thank you.


i agree with @Andrew, but of you must

p1.unique()[0] == 'v1'


Is this a bug in your app that the parameter is twice? Most people would think that should mean it has multiple values, hence it wouldn't be considered strange behavior. You can always grab the query string and parse it yourself if you don't like the default behavior.


I'm assuming you don't want it to pick up the duplicates because you don't want to have to write code in every controller action to handle that special case. The only thing I can tell you is to not allow the duplicates in the first place, or intercept the request using a filter and substitute the duplicate param values.

0

精彩评论

暂无评论...
验证码 换一张
取 消