I have an integer value in my java servlet code which is being retrieved from the database and i need to add that value to a cookie.
int k=rs.getInt(3);
Cookie c1= new Cookie("access", k);
But this line throws an error saying:
Cookie c1= new Cookie("access", k);
^
required: String,String
found: String,int
reason: actual argument int cannot be converted to String by method invocation
conversion
1 error
I understand the error but how do I go about passing a int value to a cookie. I am new to servlets. Your help would be most appreciated.
If you see the documentation of Cookie, the only constructor it has takes both the argument as
String. So, you need to convert yourintegervalue to aString.You can use
String.valueOf(int)method for that: –