0

i have develop servlet server and javaclient and want to know how to maintain session keep connecting.

now, my javaclient will call my servlet and then server will return data back to client. after client process the data and then it will call the same servlet again for other process. But the server unable retrieve existing session. So i unable to verify the client who visit before. Is there any idea? here my environment: Server: apache + jrun4 Client: java client

it return null pointer when reqType = Login, i want to keep the same session for further processing

private void getReqParameter( HttpServletRequest request, HttpServletResponse response, RandomAccessFile logFile) {

String sSessionID="", sReqType="";

String sAddress1="", sAddress2="", sAddress3="", sID="", sPwd="", sSigID="";

sReqType = (String)request.getParameter("reqType");

HttpSession sess = request.getSession(false);
if (sReqType.equals("HandShake")){
    sess = request.getSession(true);
    sSessionID = sess.getId();
    out.println(sSessionID);
    return;
}

sID = (String)request.getParameter("ID");
sPwd = (Sring)request.getParameter("Pwd");
sSigID = (Sring)request.getParameter("SigID");

if (sReqType.equals("Login")){
    sess = request.getSession(false);  
    sSessionID = sess.getId();
    return;
}     

sAddress1 = (String)request.getParameter("A1");
sAddress2 = (String)request.getParameter("A2");
sAddress3 = (String)request.getParameter("A3");

if (sReqType.equals("UpdProfile")){
    sess = request.getSession(false);   
    sSessionID = sess.getId();
    return;
}     

}
Siong Thye Goh
  • 3,518
  • 10
  • 23
  • 31
stockjoe
  • 1
  • 1

1 Answers1

0

Session afinity works with a cookie named JSESSIONID generally. The server is responsible to set this cookie in each response it sends to the client. The client must send this cookie in all its requests to maintain session afinity on the server side. The servlet container is able to find the client's session with this cookie.

Emmanuel Collin
  • 2,556
  • 2
  • 10
  • 17