Skip to content

Instantly share code, notes, and snippets.

@renanregis
Created July 24, 2018 15:03
Show Gist options
  • Save renanregis/ac19aa78ffb29b379748bb14670b4873 to your computer and use it in GitHub Desktop.
Save renanregis/ac19aa78ffb29b379748bb14670b4873 to your computer and use it in GitHub Desktop.
Getting Cookies with Javax Servlet
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
public String recuperaCookie(HttpServletRequest request){
String cookie = null;
Cookie[] cookieArray = request.getCookies();
for(Cookie c : cookieArray){
if(c.getName().equals("name_cookie")){
JSONObject json = new JSONObject(URLDecoder.decode(c.getValue()));
cookie = json.toString();
}
}
return cookie;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment