How to Test Sessions and Servlet Context on a Single Machine or Home PC?
<p>I want to Test Sessions and Servlet Context on a single computer. I am looking for an example such that I can easily show the difference of using a Session for a single user and a Context for the entire web application and I want to do it on a single stand-alone PC. How can I do it? Please explain using an example?</p>

<p>For Example - <em>NewServlet1</em> has the following code -</p>

<pre><code>    int sess = 1;
    int cont = 1;
    request.getSession().setAttribute("sess",String.valueOf(sess));
    ServletContext sc = getServletContext();
    sc.setAttribute("cont",String.valueOf(cont));
    request.getRequestDispatcher("NewServlet3").include(request, response);
</code></pre>

<p><em>NewServlet3</em> has the following code -</p>

<pre><code>    int sess = Integer.parseInt((String) request.getSession().getAttribute("sess"));
    ServletContext sc = getServletContext();
    int cont = Integer.parseInt((String)sc.getAttribute("cont"));
    out.println("sess="+String.valueOf(sess)); sess++;
    out.println("cont="+String.valueOf(cont)); cont++;            
    request.getSession().setAttribute("sess", String.valueOf(sess));
    sc.setAttribute("cont",String.valueOf(cont));
</code></pre>

<p>Now, if I open the browser I get - </p>

<p>sess = 1 cont=1 - Ok!</p>

<p>Again if I open another browser I should get - </p>

<p>sess = 1 cont = 2</p>

<p>But, I am getting the same result without increment for Context as - </p>

<p>sess = 1 cont=1 ???</p>

<p>Why so?</p>
