Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: Session id is not same


Message #1 by =?iso-8859-1?q?ashok=20sahay?= <ashok_sahay@y...> on Fri, 11 Oct 2002 14:48:33 +0100 (BST)
<%@ import javax.servlet.http.HttpSession;%>
Hi All,

I am trying write a seeion id to a cookie.For this I using a simple form ,when this is form is submitted I want to know the name and
value of the cookie.
I am trying to get the value (where i have seeionid ),I am getting some truncted value.Could any one help me ot to solve this iisue
and any idea to make this situation working will be apprecitaed.
I am using weblogic 6.01 as appl. server.
BR and thanx in advance..
ashok
The code is as follows.


<%@ import javax.servlet.http.Cookie;%>
<%@ import java.rmi.server;%>
<%@ import java.net.URLEncoder;%>
<%@page session="true";%>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>

<P>Trying to demonstrate writing session id to cookie,when cookie is set to client (browser)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<%

String sessionid=null;
Cookie c;
%>
<%!
private static String sessionId() {
String uid=new java.rmi.server.UID().toString();
return java.net.URLEncoder.encode(uid);

}

%>

<%
if(sessionid==null){
sessionid =sessionId();
c= new Cookie("sessionid",sessionid);
response.addCookie(c);
}

%>
<form action="cookies1.jsp" method="post">
<p>
<input type="submit" value="Get Cookie">
</form>

<%


Cookie[] cookies = request.getCookies();
for(int i=0; i < cookies.length; i++) {
c = cookies[i];


out.println("........********************............." +c.getValue() );        


}                  
%>


 </P>
</BODY>
</HTML>


Now when the form is submitted ,following value is coming ,why it is so..
isRequestedSessionIdFromCookie() ......true 
........********************.............277bd2%3Add350804d7%3A-7ffe 
isRequestedSessionIdFromCookie() ......true 
........********************.............4hIyZJYDu1O0haV26Ne5xxbwt0KYKawuPgbH09vwN1ZyjC56422o!1827638293!2130706433!7001!7002 


More  over why values are coming two times....


Best Regds.,
Ashok
 Yahoo! Properties Special  Buy, sell, rent...your flat, or even post an ad

  Return to Index