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



Home Answers Viewqa Java-Beginners Remember me on this computer (via cookies) in jsp servlet
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


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


Advertisement
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="dxkdyneimd@5786*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..



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
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
help me - JSP-Servlet
help me   how to open one compiled html file by clicking one button from jsp
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... for loop retrieve at all the pages. Cookie cookies [] = request.getCookies
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
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
help me on jstl- <c:url> - JSP-Servlet
help me on jstl c:url  what is jstl in java
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
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
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
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
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
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
Cookies in Servlet
Cookies in Servlet Cookies are text files that are sent by Servlet to the Web... computer. Cookies are used to track various informations. Whenever a browser...(javax.servlet.http.Cookie) method is used by servlet to send cookies to the browser
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
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
Reading excel via JSP
Reading excel via JSP   The problem is while reading cells values... CareerStart gopinath December can you help me in that and tell me how to ignore...;%=CareerStart%>></td> anyone please help me to resolve that space issue
Remember Me Login Application In JSF
:view> <html> <head> <title>Remember Me Login...<jsp:forward page="login.jsf" /> Here is the code...(this);" /> <h:outputLabel for="remember">Remember
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
help me to do it in jsp
to insert and update the topics via admin page. pls help me to do...help me to do it in jsp  if we click on a topic it should direct to another page in separate window i need to create a part of the web page which
Please help me to create this coding for pizza order application using a handheld computer.....
Please help me to create this coding for pizza order application using a handheld computer.....  You work as a programmer for IT-Tech a small... computer. You have been asked to develop a system, which runs on a PC. The software
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
Advertisements
 

 

 

DMCA.com