• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session Related Question

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to do the following:

and then
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Yes it should work.
HttpSession session = request.getSession(false);This does not invalidate the current session.
request.getSession with the parameter as false returns the currently valid session if any otherwise it returns null.
As, there is a session existing, it will return it and so the values in the session would be available.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Yes it will definately work..... and it should work irrespective of
HttpSession session = request.getSession(true/false).
vijay
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try this servlet for better understanding.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class SessionServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{

PrintWriter out = response.getWriter();
response.setContentType("text/html");

HttpSession session = request.getSession();

session.setAttribute("name", "1");

//session.invalidate();

HttpSession session1 = request.getSession(false);
System.out.println("Session1** : " + session1);
HttpSession session2 = request.getSession(true);
System.out.println("Session2** : " + session2);
String name = null;
try

{
name = (String)session1.getAttribute("name");
if (name == null)
{
name = "2";
}
}
catch(NullPointerException nu)
{

if (name == null)
{
name = "3";
}
}

out.println("Name " + name);
}
}

Regards,
M.S.Raman
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic