java - Cookie troubles with Spring MVC -
i trying cookie value using @cookie
. 400 error if cookie value null. what's wrong? controller:
public string listcontacts(map<string, object> map, httpservletresponse response, @cookievalue("flag") string flag) { response.addcookie(new cookie("flag", "in use")); ...
try setting required = false
in @cookievalue
annotation:
public string listcontacts(map<string, object> map, httpservletresponse response, @cookievalue(value = "flag", required = false) string flag) {
by default spring expects cookie header present , throws exception otherwise:
default true, leading exception being thrown in case header missing in request. switch false if prefer null in case of missing header.
alternatively, provide defaultvalue, implicitly sets flag false.
Comments
Post a Comment