hi
I am facing some problems in session tracking with Applet - Servlet communication.
It is working fine if it is HTML and Servlet communication
I am supplying the detailed code and where the help required

Applet :login:From this applet I will invoke one servlet
CheckPwd where I will perform login validation and set the
session.
I am calling the servlet from login applet as follows.

void callServlet()
{
   u=new
URL("http://192.168.148.79:8080/servlet/CheckPwd?memberid="+tfId.getText()+"&"+"passwd="+tfPass.getPassword());

   URLConnection conn = u.openConnection();
   DataInputStream din = new
DataInputStream(new
BufferedInputStream(conn.getInputStream()));
   String s = din.readLine();
}
Servlet:   CheckPwd: In this I was able to establish the session.
But I was not able to access the session in any other servlets
stored on the same server.

import java.net.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;

public class CheckPwd extends HttpServlet
{
 public void doGet(HttpServletRequest
req,HttpServletResponse res)
 {
    String memberid=req.getParameter("memberid");
    String passwd=req.getParameter("passwd");
 

// Establishing the session here

   HttpSession sess = req.getSession(true);
   if (sess==null)
   {
    out.println("invalid session");
    return;
   }
   else
    sess.putValue("memberID",memberid);
// some business logic here
 
  }
 
 }
Servlet:  CDRequestInit : This is the servlet where I am trying to
access the session which I have set in the above servlet

import java.net.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import java.lang.reflect.Method;

public class CDRequestInit extends HttpServlet
{
 

 public void doGet(HttpServletRequest
req,HttpServletResponse res)
 {

  try{
// accessing the session here
      HttpSession tempS=req.getSession(false);
      if (tempS==null)
      {
          out.println("invalid session");
          return;
      }
      else
       System.out.println("the session is"+tempS+"the
value of the session is"+tempS.getValue("memberID"));
// some business logic here
   }// end of try
    catch(Exception e)
    {
        System.out.println(e);
    }
 }
}
Here I was not able to access the session.
Session is becoming null.
Here I am calling the first servlet from the Login Applet
setting the session in the servlet CheckPwd and I am
trying to access the session in the servlet
CDRequestInit.
I did the same with by modifying the applet to HTML and
the same thing worked fine.
I think I have to write something in the applet which is
specific to HttpProtocol . I don't know how to do that.
If you have any idea please respond

regards
prasadks
[EMAIL PROTECTED]
[EMAIL PROTECTED]

 

 
 
 
 

Reply via email to