Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet set cookieless session variables in jsp

Have Programming Question? Ask it here!
 
 
 


purnima khurana
set cookieless session variables in jsp
2 Answer(s)      11 months ago
Posted in : JSP-Servlet


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


Advertisement
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
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 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
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
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
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
jsp - session - JSP-Servlet
JSP - Session  How to manage session in JSP
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 Session Object
JSP Session Object  JSP Session Object?   Session Object denotes the data associated with a specific session of user. The class... in a application where variables are stored for the entire user session. Methods
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
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
assignment of variables - JSP-Servlet
page on the server. The loginPage,jsp should something like.../jsp/ Thanks
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
How do I set environment variables from Java?
How do I set environment variables from Java?  How do I set environment variables from Java
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
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
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
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 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 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
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
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
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
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 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... the attribute value that is set using setAttribute() method within this session
JSP Session Parameter rewrite
JSP Session Parameter rewrite   ... in jsp. JSP session provides methods like getCreationtime(), getLastAccessedTime... to set the time out for each session. removeAttribute() method is used
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
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
Variables
Variables  What are the difference between Static variables, instance variables and local variables
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
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 - 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
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
PHP list all session variables
All session variables and its values are maintained by the the super global variable $_SESSION. $_SESSION is an associative array. It keeps the session.... Example of PHP List All Session Variables session1.php <?php   
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
session - JSP-Servlet
redirect the session  how i can redirect the session in any child window
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  how to enable a link only if the form in previous page is clucked  please show me your code
Disabling Session in JSP
Disabling Session in JSP  ...; In this tutorial you will learn how to disable session creation in the JSP pages. Disabling the session in some pages will improve the performance of your JSP
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
session tracking - JSP-Servlet
session tracking  hi, i m working on a real estate web site....which i have to submit as final year project. im having problem regarding session... site how do i track his session activities....how to my pages will display his
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
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
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:- String user=(String
 

 

 

DMCA.com