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

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -