Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get session id in java

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

like image 503
Tokendra Kumar Sahu Avatar asked Aug 13 '10 09:08

Tokendra Kumar Sahu


Video Answer


1 Answers

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

like image 91
YoK Avatar answered Sep 30 '22 00:09

YoK