9

I want to build an api in java to solve the security image problem occurred while moving one page to another page in any website. How can i get the session id and cookies so that i can post it with the security image string.

Thanks

Tiago Sippert
  • 1,324
  • 7
  • 24
  • 33
Tokendra Kumar Sahu
  • 3,524
  • 11
  • 28
  • 29

1 Answers1

16

Following should give session id in jsp

If you have EL enabled in your container, you can do it without the JSTL tag - ie just

<c:out value="${pageContext.session.id}"/>

or An alternative for containers without EL:

<%= session.getId() %>

Example to get Cookies is as :

<%
String cookieName = "username";
Cookie cookies [] = request.getCookies ();
Cookie myCookie = null;
if (cookies != null){
  for (int i = 0; i < cookies.length; i++) {
    if (cookies [i].getName().equals (cookieName)){
      myCookie = cookies[i];
      break;
    }
  }
}
%>

Referenced from: http://www.roseindia.net/jsp/jspcookies.shtml

YoK
  • 14,329
  • 4
  • 49
  • 67