Hi Surya,
 
As you know, javascript is executed on client side, against JSP(or Servlet) on server side.
 
Then, there is no way to add the value of a textfield to the cookie using JSP in one session.
 
But if you decide to use javascript to add the value to the cookie, you can.
 
As a reference, you can write JSP code that generates javascript code in JSP 1.0 spec.
ex)
<%@ page language=javascript %>
<%
    ... javascript code ...
%>
 
I recommend for you to post the textfield value(using form/action) to JSP that handles the value.
ex)
In page1.jsp
    :
<form action="/writecookie.jsp" method="post">
<input type=text name="name1" size=20 value="">
</form>
 
In writecookie.jsp
<%
String value1 = request.getParameter("name1");    // getting the value of textfield
 
Cookie cookie = new Cookie("name1", value1);    // adding cookie
cookie.setPath("/");
response.addCookie(cookie);
     :
%>
 
I hope it will help you.
 
from acidzazz ^!^
 
 
 
 -----Original Message-----
From: Siva Surya Kumar V [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 23, 1999 12:56 PM
To: acidzazz
Subject: Re: Re: Writing cookie in jsp

HI ...
 
    Its a good example.
    But i have a BIG probelm.
    In the line :
 
   
Cookie cookie = new Cookie("name1", "value1");
 
 
If the "value1" is a javascript variable then how should i do it ????
Mean to say i want to add the value of a textfield to the cookie .
How should i do it ???
Thanks in advance.
Surya.       
 
----- Original Message -----
From: acidzazz
Sent: Wednesday, December 22, 1999 6:44 PM
Subject: Re: Writing cookie in jsp

In JSP,
 
<%
// Adding Cookie(name1 = value1)
Cookie cookie = new Cookie("name1", "value1");
cookie.setPath("/");
response.addCookie(cookie);
 
// Getting Cookie(name1)
Cookie[] cookies = request.getCookies();
String value = "";
if (cookies != null)
{
    for (int i=0 ; i<cookies.length ; i++)
    {
        if (cookies[i].getName().equals("name1"))
        {
             value = cookies[i].getValue();
             break;
        }
   }
}
return value;
%>
 
from acidzazz ^!^;
 


 
-----Original Message-----
From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]]On Behalf Of James & Sue Ann Birchfield
Sent: Wednesday, December 22, 1999 7:03 AM
To: [EMAIL PROTECTED]
Subject: Re: Writing cookie in jsp

I don't have a code snippet available this second, but you can read/write cookies using the request/response streams.  Look at the API for the Cookie class...
 

==================================================================
James M. Birchfield                               646 Howards Loop
Software Engineer                                    Annapolis, MD
[EMAIL PROTECTED]                               (410) 897-5994
                  http://www.proteus-technologies.com
==================================================================

 
-----Original Message-----
From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]]On Behalf Of Mike Begeman
Sent: Tuesday, December 21, 1999 3:58 PM
To: [EMAIL PROTECTED]
Subject: Writing cookie in jsp

Until now, I have always used javascript to write cookies.  Does anyone have a code snippets (or suggestions on how) to write and delete cookies using JSP and/or a javabean?
 
Mike Begeman
Digital Prairie Systems, Inc.
 
 

Reply via email to