set cookieless session variables in jsp

set cookieless session variables in jsp

I want to know how to set cookieless session variables in jsp, because when I run my application multiple times, multiple tabs get open and the session variable is shared among them(because these session variables internally make use of cookie). But I don't want that . So, please tell is it possible in jsp to use cookieless session variables ?

please reply asap.... its urgent. Thanks in advance

View Answers

May 16, 2013 at 3:23 PM

hi friend,

Try this code may this will be helpful for you

index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "javax.servlet.RequestDispatcher" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Session Example</title>
</head>
<body>
<form method="post" action="user.jsp">
User:<input type="text" name="user">
<input type="submit" value="send">
</form>
</body>
</html>

user.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<body>
<%
//response.setHeader("Cache-Control","no-cache");
String user = request.getParameter("user");
if(!(user == null || user.isEmpty()))
{   
        session.setAttribute("user", user);
        String jsessionid = session.getId();
        out.println(jsessionid);
        response.sendRedirect("home.jsp?user="+user+";"+jsessionid);    
}

%>
</body>
</html>

home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>home</title>
</head>
<body>
<p>Hello, <%= session.getAttribute( "user" ) %></p>
<%
Cookie cookie = null;
Cookie[] cookies = null;

if(!(session.getAttribute("user")==null))
{
Cookie userName = new Cookie("us",
          request.getParameter("user"));
Cookie sId = new Cookie("sessionId",
          session.getId());
cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++)
{
    cookie = cookies[i];
    //out.println(cookie.getName());
    if((cookie.getName( )).compareTo("JSESSIONID") == 0 ){
       cookie.setMaxAge(0);
       response.addCookie(cookie);
      // out.println(cookie.getName()+" deleted");
}
}
}
%>
</body>
</html>

May 16, 2013 at 5:31 PM

thanq sir... but what is the usage of cookies here ???









Related Tutorials/Questions & Answers:
set cookieless session variables in jsp
set cookieless session variables in jsp  I want to know how to set cookieless session variables in jsp, because when I run my application multiple... that . So, please tell is it possible in jsp to use cookieless session variables
How to implement session variables - JSP-Servlet
How to implement session variables  Hi, I have a servlet which gets parameter from a jsp page(x). it is stored in a variable in servlet as shown below. the servlet response is another jsp page(y). I should put the value of amp
Advertisements
JSP - Update displayed content & session variables when user clicks on a button - JSP-Servlet
JSP - Update displayed content & session variables when user clicks on a button  Hi, I'm trying to setup a form in which the user can click... JSP to do some internal check and then increment the value of a number
session variables server side
session variables server side  how to hold session variable for server side..?   request.getSession().setAttribute("wellSelection", uid
JSP - Update displayed content & session variables when user clicks on a button - JSP-Servlet
JSP - Update displayed content & session variables when user clicks... JSP to do some internal check and then increment the value of a number... combination of JSP and javascript would work since my knowledge base is in Java. Here
jsp - session - JSP-Servlet
JSP - Session  How to manage session in JSP
How can we register the variables into a session?
How can we register the variables into a session?  How can we register the variables into a session
Variables in a Servlet - JSP-Servlet
Variables in a Servlet   Hi, I'm using some variables in a servlet1 (which i get from a jsp, like "String x = request.getParameter("xyz");"). the servlet response is a jsp page which after taking some more parameters gets
jsp scope variables - JSP-Interview Questions
jsp scope variables  what is the importance of page,session,request n application scope variables in JSP?Am not understanding where which scope..., the jsp object is accessible from pages that belong to the same session from
JSP Session Object
JSP Session Object  JSP Session Object?   Session Object denotes the data associated with a specific session of user. The class or the interface name of the object session is http.HttpSession. The object session
how to initialise variables in jsp?
how to initialise variables in jsp?   1. what is the problem in the folloing jsp <%@ page import="net.viralpatel.struts.helloworld.form.LoginForm" %> <%@ page language="java" contentType="text/html
Jsp Scope Variables - JSP-Interview Questions
Jsp Scope Variables  what is the importance of page,session,request n application scope variables in JSP?Am not understanding where which scope variable we have to use in programs..let me know when we have to use them seperately
JSTL: Set Session Attribute
and jsp. That's why the jstl is too easy.  In jstl we will set the session...JSTL: Set Session Attribute     ... are using the jstl and there is a need to set a variable in the session. You all know
pasing variables in jsp file - JSP-Servlet
pasing variables in jsp file  How can more than one pages of jsp files share variables and how can one pass local variables from one jsp file to another jsp file?  Hi Friend, To pass variables from JSP file
session in jsp - Java Beginners
  Hi friend, session is implicit object in jsp. using session oject in jsp. first u set using following methods String name... let me know how to create a session in jsp. Session for jsp with two side
session tracking in jsp
session tracking in jsp  hi... i am creating 3 jsp pages ie. login.jsp,display.jsp,userinput.jsp.. i am able to pass the value from login.jsp to display.jsp using session set attribut ang get attribute.. but same ting
assignment of variables - JSP-Servlet
page on the server. The loginPage,jsp should something like.../jsp/ Thanks
how to set the values in jsp
how to set the values in jsp  how to set the values text boxs in jsp frm dbase via servlet
How do I set environment variables from Java?
How do I set environment variables from Java?  How do I set environment variables from Java
How do servlets work? Instantiation, session variables and multithreading
How do servlets work? Instantiation, session variables and multithreading  How do servlets work? Instantiation, session variables and multithreading
Jsp Scope Variables - Java Interview Questions
Jsp Scope Variables  what is the importance of page,session,request n application scope variables in JSP?Am not understanding where which scope... in advance.  Hi Friend, JSP Scope Variables: Page scope-It makes
how to get javascript variables into jsp - JSP-Servlet
how to get javascript variables into jsp  How to pass variables from java script into jsp page  Hi Friend, Try it: 1)pass.jsp: var msg="Hello World" window.location.href="show.jsp?value=" + msg
Set Parameter - JSP-Interview Questions
Set Parameter  Hi, could someone please explain the process of setting parameter in the session from JSP with the help of code? Thanks!  Hi,In your JSP page use the Set Tag, and set the scope attribute
Duplicated Session Variables
Duplicated Session Variables     ... a new session variable because it has been created by the JSP container for you... name. Consider we have declared a session variable true in jsp page <%@ page
set cookie in jsp
set cookie in jsp  How set cookie in jsp ?   Cookie is a small piece of information which is stored in user's computer. Web server uses cookie to identify the user in the next time visit.Example : <% Cookie
Session Timeour - JSP-Servlet
Session Timeour  Hi, How to create a session timeout page in JSP? Session timeout should happen after 15 mins of idle instance. Thanks ... the following link: http://www.roseindia.net/jsp/jsp-session-parameter
Session Problem in JSP - JSP-Servlet
Session Problem in JSP  I have developed a online feedback form in JSP platform. I have created normal session in JSP page. It is running in my... then the session is not working. I have not used EJB. Please tell me how can I track session
Session removing - JSP-Servlet
Session removing  Hi, I am destroying session by using session.invalidate() in JSP but I am not able to destroy it completely can anyone help me... has been in session using session. setAttribute() but at log off I am using
session in jsp
session in jsp In this section you will learn about session in JSP. Here you will learn about how to use the HttpSession in JSP. session in JSP is defined... interval of user with this session that a Servlet container will set for accessing
session concept - JSP-Servlet
session concept  Hello friends, How can we track unexpectedly closing a window when a jsp project running with session concept. And this tracking should update the log in status in data base
JSP Session Parameter rewrite
JSP Session Parameter rewrite   ... in jsp.ADS_TO_REPLACE_1 JSP session provides methods like getCreationtime...() method is used to set the time out for each session. removeAttribute() method
session - JSP-Servlet
session  How to manage session for a particular user ..using session... then userid is set in your session.RegardsAmar  Answer:If you get id as a integer from mlid field then userid is set in your session.RegardsAmar
Session concept - JSP-Servlet
Session concept  Hai friends, I am doing a jsp project with session concept. If one person is not accessing his logged window for more than 10 minutes it gets automatically log out.Anybody explain me the reason
JSP Implicit object "session"
about JSP implicit object "session" with an example. Session Object... variables are stored for the entire user session. The session objects do not lose the variables and the value remains for the user?s session. The concept
Scripting Variables in JSP Custom Tag
Scripting Variables in JSP Custom Tag   ... are variables that are available to the JSP page when any JSP page is called. Scripting... of JSP page we mean page level variables declared by the JSP page. You can access
JSp session time out
JSp session time out  Consider a case where we are working on a java... for it??   If you want to make session timeout programatically, you can use... the maximum time in seconds before a session becomes invalid. Its syntax
Session In JSP
Session In JSP      ... of World Wide Web (WWW).    Session Management in JSP...; Cookies in JSP When cookie based session management is used, a token
Disabling Session in JSP
in the JSP file by setting the session attribute to false. Set the session... Disabling Session in JSP  ...; In this tutorial you will learn how to disable session creation in the JSP pages
Clearing session in jsp
Clearing session in jsp  i have developed a web appilcation using jsp and when user try to logout, session is not clearing even though i have used session.invalidate() and session.removeAttribute("username
how to set time in jsp page
how to set time in jsp page   I need code for set the time in jsp code .iam using struts frame work back end oracle 10g ide is eclipse 6.0
Session Tracking JSP - JSP-Servlet
Session Tracking JSP  Respected sir/madam, I am R.Ragavendran.. I Immediately need a coding for session tracking in JSP. Actually when... information. http://www.roseindia.net/jsp/loginstatus.shtml Thanks
session maintainence - JSP-Servlet
session maintainence  if the logout link is clicked in the main page.... login application in jsp function validateForm(theForm...; } Login Application in JSP
session value not get in many jsp page.
session value not get in many jsp page.  I am using servlet to set session by following code :- HttpSession session=request.getSession(false...,response); and get session value on jsp page by follwing:- (adsbygoogle
session - JSP-Servlet
successfully login set the user in session <% String userName...session  please send me an example code for session tracking using... that the Web server can't easily remember previous transactions.In session tracking
session - JSP-Servlet
redirect the session  how i can redirect the session in any child window
ModuleNotFoundError: No module named 'django-cookieless'
ModuleNotFoundError: No module named 'django-cookieless'  Hi, My... named 'django-cookieless' How to remove the ModuleNotFoundError: No module named 'django-cookieless' error? Thanks   Hi, In your
session maintainence - JSP-Servlet
session maintainence  how to enable a link only if the form in previous page is clucked  please show me your code
arraylist with session - JSP-Servlet
arraylist with session  hi how can an arraylist stored in session.. and also how will it access?? pls give me the details with sample code..   Hi friend, Code to solve the problem : Thanks
session management - JSP-Servlet
session management  hi friends... hope u all dng fine. i am dng... think i am not using session management properly. and also in my web.xml file i said session timeout 1min. even it is also not working.wht to do :-( i will give
servlet session - JSP-Servlet
the counter if new user logs on and decrement if session times out or user  Hi... on and decrement if session times out or user log offs.Thanks

Ads