I wrote a simple servlet which i access through a html form.In the
servlet i am putting out the session object and the session id. when
i access for the second time the servlet from the same browser window,
i get a new session every time but the same session id(the same client).
i am doing something wrong but i don't see what. can you please help?
thanks
mohammed
hier is the code:
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class SessionTest extends HttpServlet {
public void init(ServletConfig config)throws ServletException{
super.init(config);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
}
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String name = req.getParameter("name");
HttpSession session = req.getSession(true);
String passwd= req.getParameter("passwd");
out.println("user 1. mal ausgeben: : :" + name);
out.println("passwd 1. mal ausgeben : : :" + passwd);
out.println(" is the sesion new? : : : " +session.isNew());
out.println( "this is the session id: : : " + session.getId());
out.println(" and this is the HttpSession object : : : : :" + session);
session.putValue("name",name);
session.putValue("passwd",passwd);
out.println("user 2. mal ausgeben: : :" + session.getValue("name"));
out.println("passwd 2. mal ausgeben : : :" +
session.getValue("passwd"));
out.println("now are following all the session in the context :");
HttpSessionContext context = session.getSessionContext();
Enumeration ids = context.getIds();
while(ids.hasMoreElements()){
String id = (String)ids.nextElement();
out.println("this is the session from context.getsession:" +
context.getSession(id)+"\n");
out.println("and this is the matching id from from context.getIds()=
" + id +"\n");
String user =(String)context.getSession(id).getValue("name");
String pass =(String)context.getSession(id).getValue("passwd");
out.println("user:" + user);
out.println("passwd:" + pass);
}
}
public void destroy(){
}
}
hier is the ffirst request ouput
user 1. mal ausgeben: : :m,m, passwd 1. mal ausgeben : : :m, is the
sesion new? : : : true this is the
session id: : : 935769782086258570 and this is the HttpSession object :
: : :
:com.livesoftware.jrun.JRunSession@3a65835 user 2. mal ausgeben: : :m,m,
passwd 2. mal
ausgeben : : :m, now are following all the session in the context : this
is the session from
context.getsession:com.livesoftware.jrun.JRunSession@3a65835 and this is
the matching id from
from context.getIds()= 935769782086258570 user:m,m, passwd:m,
hier is the second request output
user 1. mal ausgeben: : :gg passwd 1. mal ausgeben : : :gg is the sesion
new? : : : true this is the
session id: : : 935769782086258570 and this is the HttpSession object :
: : :
:com.livesoftware.jrun.JRunSession@1b425835 user 2. mal ausgeben: : :gg
passwd 2. mal
ausgeben : : :gg now are following all the session in the context : this
is the session from
context.getsession:com.livesoftware.jrun.JRunSession@1b425835 and this
is the matching id
from from context.getIds()= 935769782086258570 user:gg passwd:gg
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html