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

Ads

 
 

Share on Google+Share on Google+

Anuj Kumar
Remember me on this computer (via cookies) in jsp servlet
2 Answer(s)      6 years and 11 months ago
Posted in : Java Beginners

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

Ads
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 on this computer (via cookies) in jsp servlet
Remember me on this computer (via cookies) in jsp servlet  Remember me on this computer (via cookies) in jsp servlet   Hi, Here is the detail of using cookies to identify the user. In Servlet or JSP you can set
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
Advertisements
servlet cookies - JSP-Servlet
servlet cookies  helo sir i need a servlet program which create a cookie and add userid's and passwords and read the userid and password from... in the webinf.xml and access them in the servlet by using the getInitParameters() method
help me - JSP-Servlet
help me   how to open one compiled html file by clicking one button from jsp
cookies - JSP-Servlet
this problem. please help me I'm waiting for your valuable reply thanks in advance <% Cookie[] cookies = request.getCookies(); if (cookies == null) cookies = new Cookie[0]; String name
Please answer me - JSP-Servlet
servlet or jsp codes that I can use to insert and retrieve image from MSSQL 2000 NOT MySQL. Please assist me and for other questions I've asked before
plz help me!!!!!!!! - JSP-Servlet
plz help me!!!!!!!!  i`ve set the environment varaibles for tomcat as well as jdk.. but i`m not understanding where i`ve to save my servlet..i.e.... there are compilation errors.. plz do help me.   make sure that you did
Plz Plz reply Me - JSP-Servlet
the image.. I request you to remember the code which you have provided for me..., Read for more information. http://www.roseindia.net/jsp/pop-window.shtml
how to maintain cookies throughout the website - JSP-Servlet
how to maintain cookies throughout the website  Hi to All, We... reply me as soon as possible. Thanks, Lakshminarayana  Hi friend, Read for more information. http://www.roseindia.net/jsp
how to maintain cookies throughout the website - JSP-Servlet
how to maintain cookies throughout the website  Hi to All, We... reply me as soon as possible. Thanks, Lakshminarayana  Hi friend... for loop retrieve at all the pages. Cookie cookies [] = request.getCookies
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
help me on jstl- <c:url> - JSP-Servlet
help me on jstl c:url  what is jstl in java
setting the cookies in another domain - JSP-Servlet
setting the cookies in another domain  Hello, how can i set the cookies in another domain
Computer - JSP-Interview Questions
the image button through my servlet with out using the anchor tag kindly give solution... ForwardServlet extends HttpServlet{ private static final String forwardTo = "/jsp/ResultServlets"; private static final String includeIn = "/jsp/ResultServlets
Plz reply me sir Its urgent - JSP-Servlet
Plz reply me sir Its urgent  Respected Sir/madam, I am R.Ragavendran..Actuaaly,I request you to remember the code which you have provided for me using radio buttons.. You have used the following syntax for checking whether
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session   sig
Dialling from computer with other phone via modem card
Dialling from computer with other phone via modem card  Hello... a phone number through a modem connected in the computer. During research I ended up... scratch. It would be helpful if anyone pass me some reference links, tutorials
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
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session   sig   Hi Friend, Please visit the following link: http://roseindia.net/jsp/bank.shtml Thanks
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
Cookies in JSP
depend on them. Second, as the author of JSP/servlet that use cookies, you...Cookies in JSP In this section, we will discuss about handling cookies in JSP... let you customize the look of the main page. They use cookies to remember what
servlet/jsp - JSP-Servlet
servlet/jsp  Thanks for ur feedback! But this program shows... package.org.apache.commons.fileupload does not exists please help me its urgent... this problem you remember few points. 1.Download the jar "commons-fileupload-1.2
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
servlet and jsp - JSP-Servlet
servlet and jsp  can any one give me jsp-servlet related project-its urgent- 1-chat application 2-bug tracking system 3-online shopping 4-online...://www.roseindia.net/jsp/bank.shtml Thanks
servlet/jsp - JSP-Servlet
servlet/jsp  hi, get me the source code to upload all file formats in servlet/jsp plaese help me as soon as possible its urgent!!! by saravanan.k  Hi friend, Code to help in solving the problem
Jsp-Servlet
Jsp-Servlet  how can i display the values in jsp pages as list from servlet ? can you help me out plz ? thanks
Reading cookies in jsp
Reading cookies in jsp   How read cookies in jsp ?   Creates a cookie, a small amount of information sent by a servlet to a Web browser... uniquely identify a client, so cookies are commonly used for session management
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
Distribute Servlet or JSP on network - JSP-Servlet
Distribute Servlet or JSP on network  Sir Even after successfully deploying a servlet or JSP program on J2EE web server I am not been able..." For any more problem on Servlet and Jsp visit to : http://www.roseindia.net