Remember me on this computer (via cookies) in jsp servlet

Ads
 

Remember me on this computer (via cookies) in jsp servlet

Remember me on this computer (via cookies) in jsp servlet

View Answers

October 25, 2010 at 7:27 PM

Hi,

Here is the detail of using cookies to identify the user.

In Servlet or JSP you can set the cookies for a user and then add it to the response object.

Here is the code of setting the cookies:

<%@ page language="java" import="java.util.*"%>
<%
// Generate this key And save In database And Set as cookies
String userIdendificationKey="[email protected]*54904";


Date now = new Date();
String timestamp = now.toString();
Cookie cookie = new Cookie ("userIdendificationKey",userIdendificationKey);
//Set the required cookies age
cookie.setMaxAge(365 * 24 * 60 * 60);
//Then add the cookies
response.addCookie(cookie);
%>

You can read the cookies and idenfity the user. Here is the sample code:

<%
String userIdendificationKey = "";
Cookie cookies [] = request.getCookies ();
Cookie myCookie = null;
if (cookies != null)
{
 for (int i = 0; i < cookies.length; i++) 
    {
    if (cookies [i].getName().equals ("userIdendificationKey"))
    {
        userIdendificationKey = cookies[i];
        break;
    }
   }
}
//Then use the userIdendificationKey And Get the user name from database 
//To identify the user
//Do whatever you want after identifying the user
%>

Let me know in the same post if you have any query.

Thanks


January 17, 2011 at 1:15 PM

hi,

Then what will happen if the customer deletes the cookies from browser menu ???

My requirement is to set the cookie in clients machine and retrieves whenever it needs for the application..

Ads









Related Tutorials/Questions & Answers:
Remember Me
Remember Me  How to Create a PHP AutoLogin ('Remember Me') Feature using Cookies????   Hi Friend, Please visit the following links: http.../tutorial/php/php-cookies.html http://www.roseindia.net/php/cookies
how to send email please give me details with code in jsp,servlet
how to send email please give me details with code in jsp,servlet  how to send email please give me details with code in jsp,servlet
Advertisements
ModuleNotFoundError: No module named 'django-remember_me'
ModuleNotFoundError: No module named 'django-remember_me'  Hi, My... named 'django-remember_me' How to remove the ModuleNotFoundError: No module named 'django-remember_me' error? Thanks   Hi, In your
Servlet - JSP - JSP-Servlet
Servlet - JSP  i used arraylist in servlet as shown ArrayList...",total); when I code this like in my jsp <%ArrayList<Integer> data= new... typecast or anything else. I'm sure mu k[i] have some value. please let me know
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP... button, send the request to a servlet .Once the servlet receives the request, it need to create a thread. so please help me in writing this code
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP... button, send the request to a servlet .Once the servlet receives the request, it need to create a thread. so please help me in writing this code
JSP-Servlet
JSP-Servlet  Hi have created a JSP page and I need to print it when the user clicks on the print button. I have put a print button on the JSP page. Can somebody plz help me out with the Servlet page coding
servlet and jsp
servlet and jsp  how to connect an jsp and an servlet without connecting to database
Help me to create a sharing text just like facebook using jsp servlet and oracle
Help me to create a sharing text just like facebook using jsp servlet... some thing into public! so please help me to do this project. And one more thing is that i want to pass a value to servlet without refreshing the whole jsp
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
jsp servlet
how to write a code to Create a JSP with one text field to enter the URL  i dont know how to write a code to Create a JSP with one text field... to a servlet .Once the servlet receives the request, it need to create a thread
jsp servlet
code to Create a JSP with one text field to enter the URL and a submit button  i dont know how to write a code to Create a JSP with one text field... the request to a servlet .Once the servlet receives the request, it need to create
session realtime usage program simple jsp program or servlet ,which understands me importance of session
session realtime usage program simple jsp program or servlet ,which understands me importance of session  I knew importance of session theoritically like client state storage scope.,but jsp or servlet realtime simple session
Servlet - JSP - JSP-Servlet
Servlet - JSP  Here is my complete code. all my code is running with out any error. the for loop in servlet is running as many times as my checkboxes.... They are returning -1 and -1. please let me know how to resolve it. Thanks
coding in jsp & servlet
coding in jsp & servlet  plz... provide me coding of "online examination system" in jsp & servlet
Example questions of JSP & Servlet
Example questions of JSP & Servlet  Give me some JSP & Servlet Question and their answers
Java Servlet - JSP-Servlet
Java Servlet   Hello Sir Could you help me in understanding directory Structure for servlet page in eclipse (IDE). I save my Sevlet in WEB-INF but it is not displaying, it is displaying code of servlet. Process used
jsp and servlet
the data and delete the data,using jsp and servlet...jsp and servlet  I want to create a login form,which have many fields,and have a connectivity with thwe oracle database,and login form will have
jsp and servlet
jsp and servlet  hello friends just want to create a jsp page... login from login page and if we submit it shud be validated in a servlet using... links: http://www.roseindia.net/jsp/loginbean.shtml http://www.roseindia.net
EL in jsp - JSP-Servlet
? in case please let me know  What version of JSP ru using?? see.... The default mode for JSP pages delivered using a Servlet 2.3 or earlier descriptor... for JSP pages delivered with a Servlet 2.4 descriptor is to evaluate EL
servlet and jsp
servlet and jsp  how can i get a form question from a database... with servlets and jspīs   Have a look at the following links: http://www.roseindia.net/jsp/paging.shtml http://www.roseindia.net/jsp/navigation
jsp and servlet
jsp and servlet  If i want to get dynamic value in html textbox or in jsp,then how can I get the value,how the value will be transfered from servlet... or date type.........Thanx in advance.....Kindly help me...........   1
How to call servlet in JSP?
How to call servlet in JSP?  How to call servlet in JSP
jsp servlet
jsp servlet  dispay hindi in jsp
SERVLET AND JSP
SERVLET AND JSP  If i want tio create a login form using SUBMIT,ADD...,kindly give me reply as soon as possible............   1)register.jsp...;For more information visit the following links: http://www.roseindia.net/jsp/user
SERVLET AND JSP
SERVLET AND JSP  If i want tio create a login form using SUBMIT,ADD...,kindly give me reply as soon as possible............   1)register.jsp...;For more information visit the following links: http://www.roseindia.net/jsp/user
Servlet,Jsp
Servlet,Jsp   This is my requirement?I have a login page and register page?If I give the url as http://localhost:8080/Project/Login.jsp ,it should go...?.can u help me in showing invalid session on giving dat url
calling servlet from jsp
calling servlet from jsp  how to call a servlet from jsp
JSP - JSP-Servlet
JSP  How to store selected combo value in a String variable.. in JSP without AJAX. pls.... help me....  Hi friend, Using Jquery to store selected combo value in jsp : http://www.roseindia.net/ajax/jquery
JSP - JSP-Servlet
JSP  This is the error which i got in my JSP page. "The value for the useBean class attribute SQLBean.DbBean is invalid." please help me...://www.roseindia.net/jsp/java-beans.shtml Thanks
Servlet Question - JSP-Servlet
Servlet Question  I want to call one servlet when the browser window is closed by User

Ads