File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Session Related Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Related Question" Watch "Session Related Question" New topic

Session Related Question

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Is it possible to do the following:

and then
B Mampilli
Ranch Hand

Joined: Aug 05, 2002
Posts: 61
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.

vijaykumar shah

Joined: Jul 02, 2003
Posts: 23
Yes it will definately work..... and it should work irrespective of
HttpSession session = request.getSession(true/false).
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
You can try this servlet for better understanding.
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionServlet extends HttpServlet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

PrintWriter out = response.getWriter();

HttpSession session = request.getSession();

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


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

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

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

out.println("Name " + name);

I agree. Here's the link:
subject: Session Related Question
It's not a secret anymore!