Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Session Related Question

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to do the following:

and then
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Happily living in the valley of the dried frogs with a few tiny ads.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic