cookie creation without specifying the vaue

cookie creation without specifying the vaue

View Answers

October 31, 2008 at 3:50 PM

Hi friend,


I have created cookie and store the cookie value of username.

String username = request.getParameter("username");


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class UseCookies extends HttpServlet {
public void doGet ( HttpServletRequest request,
HttpServletResponse response )throws ServletException, IOException {
PrintWriter out;
response.setContentType("text/html");
out = response.getWriter();

String username = request.getParameter("username");
Cookie cookie = new Cookie("username",username);
cookie.setMaxAge(100);
response.addCookie(cookie);

out.println("<HTML><HEAD><TITLE>");
out.println(" Use of cookie in servlet");
out.println("</TITLE></HEAD><BODY BGCOLOR='cyan'>");
out.println(" <b>This is a Cookie example</b>");
out.println("</BODY></HTML>");
out.close();
}
}

For any problem plz give in details and source code and visit to :

http://www.roseindia.net/servlets/use-cookie-servlet.shtml
http://www.roseindia.net/servlets/send-cookies-in-servlets.shtml

Thanks









Related Tutorials/Questions & Answers:
cookie creation without specifying the vaue - Java Beginners
cookie creation without specifying the vaue  how do we create cookies using java servlets by just specifying the name and not providing the value for it.because my colleague said once cookie is created value will be assigned
connect database without specifying dsn name in java
connect database without specifying dsn name in java  How can i connect the database with my application without specifying the dsn name by using jdbc & odbc..... i have saw this code on the web-site try
Advertisements
Drop constraint of table in oracle without specifying constraint name
Drop constraint of table in oracle without specifying constraint name  I create my table in oracle with check constraint but I forgot constraint name.Now I want to drop constraint of my table without specifying constraint name
without ;
without ;  can u give me an example of a program without
without ;
without ;  can u give me an example of a program without
Creation of xml
Creation of xml  Hi, I need to fetch details from my database and to create a xml file containing all those datas...My database datas are in key value pair... AppID Label Value 12345 Applicant name XXXX 12345 Masterno
Creation of methods
Creation of methods  I have a only single class and its having only one method ie., main method only.... i need to develop another method that is to reduce my switching code package org.bankPackage.one; import java.util.Scanner
How to: generic array creation
How to: generic array creation  How to: generic array creation
Clear cookie example
Cookie' button. It floats the alert box showing the successful creation... Clear Cookie Example    .... The example below shows how to delete the cookie from the browser using
object creation - Subversion
object creation in Java  In how many ways we can create objects in Java
Specifying Security for Basic Authentication using @ServletSecurity
In this section, you will learn about how to specifying security for basic authentication using @ServletSecurity
object creation - Java Beginners
object creation  I need object creation in depth(with stack,pc registers).Any one can provide me if possible with video/audio
creation of installer - Java Magazine
creation of installer  plz tell me how can be create installer for any developed application in java?  visit the following url izpack.org.. it will helps u
exe file creation - JDBC
exe file creation   hi i have done a project in java swings.project name is format migrator.means db migrator. now my aim is create EXE FILE for my project. pls do consider
without scanner
without scanner  a company need a system to store the data about the employees , the number of employees is dynamic , you need to store the following attributes : name , age , salary and note that we need to solve it using array
creation button using objective c
creation button using objective c  creation button using objective c
Cookie in jsp
Cookie in jsp  Define Cookie in jsp ?   The cookie file is a file that resides on the client machine. It contains data passed from web... returns. The web site only has access to the part of the cookie file that represents
Persistent Cookie
Persistent Cookie  What Is a Persistent Cookie?   Hi friends, A persistent cookie is a cookie which is stored in a cookie file permanently... because users can open cookie files see the cookie values. Thanks
XSD Creation. - WebSevices
XSD Creation.  When I try to generate xsd from java object. It is generating XSD file finely. But the problem is it isgenerating XSD file elements in alphabetical order. can u please sujest me how can we do that one. I tried
creation of a form - JSP-Servlet
creation of a form  how to create a question paper using JSP code  Hi Friend, We have taken radiobuttons in our application, you can take textarea, textfield etc. Create a table ans(ques,op1,op2,op3,op4,op5,ans
creation of database - SQL
creation of database  hi, where to and how to execute SQL queries?   Hi nanju mysql>CREATE DATABASE search; mysql> SHOW DATABASES; mysql> USE search mysql>create table Emp (fname VARCHAR(20
Random Creation of password
Random Creation of password  Dear Sir I have created a form with some details in it.When clicking on the submit button it gives me a password .....Details and the password is saved in the database....The password has
xml file creation in java
xml file creation in java  how to create xml file in java so that input should not be given from keyboard. and that file should be stored.   Please visit the following links: http://www.roseindia.net/tutorial/java/xml
Session creation and tracking
Session creation and tracking  1.Implement the information persistence across servlet destroy or servlet container start/stop. Write a servlet such that when it is stopped (either by container shutdown or servlet stop
bean creation exception
bean creation exception  hi i am getting exception while running simple spring ioc program Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class
set cookie in jsp
set cookie in jsp  How set cookie in jsp ?   Cookie... cookie to identify the user in the next time visit.Example : <% Cookie cookie = new Cookie("ClientName","Roseindia"); cookie.setMaxAge(3600
How to reset a cookie?
How to reset a cookie?  How to reset a cookie
What Is a Persistent Cookie?
What Is a Persistent Cookie?  What Is a Persistent Cookie?. Explain
How to destroy a cookie?
How to destroy a cookie?  How to destroy a cookie
xml creation in java
xml creation in java  HI, I need a java program to create an xml file... therez a tutorial in your site to create an xml file at http://www.roseindia.net/xml/dom/CreatXMLFile.shtmlADS_TO_REPLACE_1 but this isn't creating
creation of table using a Java swing
creation of table using a Java swing  how to create a table dynamically in Java swing
Chatbox creation problem
Chatbox creation problem  i have one chat box in my web site and i assigned fixed position to that div.that is workin in mozill but it is not working in ie . thank you`print ("<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
forums creation using spring with hibernate?
forums creation using spring with hibernate?  how to write mandatory fields with validations in forms using spring with hibernate? give me detailed example
PDF creation in JAVA - JSP-Servlet
PDF creation in JAVA  HI! Good morning.... I want to create pdf file and i want to write something into pdf file....before creation. Upto creation i have done but how to write data into pdf. File Writer is not working
Action without a form.
Action without a form.  Can I have an Action without a form
Setting Cookie
Setting Cookie  setcookie function is used for setting up a cookie. In the following example, if you use $_COOKIE command, you will view one cookie value, and if you see print_r ($_COOKIE), you will view all cookie value. We have
cache creation in java - Java Beginners
cache creation in java  Hi All, I am planing to create cache in my web application. please send me the some sample code to create cache by using org.apache.oro.utils package. please help me out. Thanks, mln15584
Cookie methods in jsp
Cookie methods in jsp   Define cookie methods in jsp ?    Cookie methods : clone() getComment() getDomain() getMaxAge() getName() getPath() getSecure() getValue() getSecure() getVersion
Cookie Handling - JSP-Servlet
Cookie Handling  Hi i am working on the Application in which i... on a per user setting (probably via a cookie). This would of course mean that when..."; //get the array of cookies. Cookie cookies [] = request.getCookies
checkbox custom tag creation in jsf
checkbox custom tag creation in jsf  how to create check box custom tags with the following functionality: 1.there must be two checkboxes 2.when the first box is checked it must populate the names of bikes,when the second
Write cookie and session to textfile?
Write cookie and session to textfile?  I want to store all data from user submisstion into a textfile, include session and cookie. Thanks
Removing existing cookie in jsp
Removing existing cookie in jsp  How remove existing cookie in jsp ?   If you want to remove an existing cookie, you can use the method setMaxAge() of that cookie object to set its timeout to zero.Example <%@page
creation an dmanipulation of trees - Java Beginners
creation an dmanipulation of trees  Hi guys? pls i want to find out a hind aboout what these terms or phrases means, -To create and manipulate a Binary Search Tree -To use the Java API's Stack in conjunction with other
Delete Cookie
the cookie through setting session.  In the given example, we have set the value of cookie after one month of generating and before one hour of system date. ADS_TO_REPLACE_1 For deleteing the cookies, you will have to set the cookie
Double To Int Without TypeCasting
Double To Int Without TypeCasting  How to convert Double to Int without using typecasting?   class ConvertDoubleToInt { public static void main(String[] args) { double d=25.5; int num=new
Application without Interface Builder!!
Application without Interface Builder!!  Can we make our iphone application without Interface Builder???   hello, yes , it is possible to make an iphone application without interface builder..ADS_TO_REPLACE_1 we can
ModuleNotFoundError: No module named 'music-album-creation'
ModuleNotFoundError: No module named 'music-album-creation'  Hi...: No module named 'music-album-creation' How to remove the ModuleNotFoundError: No module named 'music-album-creation' error? Thanks   Hi
ModuleNotFoundError: No module named 'music-album-creation'
ModuleNotFoundError: No module named 'music-album-creation'  Hi...: No module named 'music-album-creation' How to remove the ModuleNotFoundError: No module named 'music-album-creation' error? Thanks   Hi
ModuleNotFoundError: No module named 'music-album-creation'
ModuleNotFoundError: No module named 'music-album-creation'  Hi...: No module named 'music-album-creation' How to remove the ModuleNotFoundError: No module named 'music-album-creation' error? Thanks   Hi
ModuleNotFoundError: No module named 'music-album-creation'
ModuleNotFoundError: No module named 'music-album-creation'  Hi...: No module named 'music-album-creation' How to remove the ModuleNotFoundError: No module named 'music-album-creation' error? Thanks   Hi

Ads