Simplifying cookies in JSP

I'm trying to figure out a simpler way to send cookies from JSP/servlets.
So far, I've created a cookie() method, in a utility bean called: util.classpublic Cookie cookie(String name, String value, String path, int age) {
  Cookie m_cookie = new Cookie(name, value);
  m_cookie.setPath(path);
  m_cookie.setMaxAge(age);
  return m_cookie;
}From my JSP, I do the following:
response.addCookie( util.cookie("foo_name", "foo_value" ,"/", -1) );My question is: Is there a way to send the cookie, without explicitly calling, response.addCookie()?
Is there some way to call, response.addCookie(), internally, from the cookie() method, itself?
Dimitri

Nevermind. I figured it out.

Similar Messages

  • How to use cookies in jsp

    Hi all,
    I'm new to jsp, please let me know how to use cookies with jsp.
    I have three web applications, in run time I have to switch from one application to another application based on single login page. I have taught cookies are one of the solution. But while I'm googling I unable to get such a good material.
    please give some examples,
    Thanks in advance.
    achchayya

    Read a cookie in jsp
    HttpSession session = request.getSession();
    Cookie cookie_session = getCookie(request, "COOKIENAME");
              if (cookie_session == null) {
                   sesID = session.getId();
              } else {
                   sesID = cookie_session.getValue();
              }or
    get all cookie in the browser
    This gets all the cookies and according to the cookie name given u can get the cookie value
    Cookie[] cookies = request.getCookies();
              if (cookies != null) {
                   for (int i = 0; i < cookies.length; i++) {
                        if (cookies.getName().equals(cookieName))
                             return cookies[i];
                   }but i am not sure if this works for ur requirement try and see                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Sending Cookie to JSP Through Servlet

    I am trying to read a cookie through JSP and cookie is defined in Servlet.
    Here is what happening?
    First JSP, user click on a hyperlink to select a category and that invokes servlet. Servlet has to pass selected category to another JSP page through a cookie.
    Here is the code for Servlet
    Cookie c1 = new Cookie("selectedCatgId", catgId);
    response.addCookie(c1);
    Target is a JSP, which I am calling through
    RequestDispatcher dispatcher;
    dispatcher = request.getRequestDispatcher("target.jsp");
    In target.jsp, when I am reading the Cookie
    Cookie cookies[] = request.getCookies();
    Cookie currCookie;
    if (cookies != null) {
    for (int i=0; i<cookies.length; i++) {
    currCookie = cookies;
    if (currCookie.getName().equals("selectedCatgId")) {
    parentCatgId = currCookie.getValue();
    This shows me one previous value of the cookie, not the current value I passed through the servlet. Not what I set in servlet.
    Can anybody help in this? I am not sure where I am wrong?
    Thanks, Vikas

    You are passing information on the server side. So, you should use attributes and not cookies.
    Also, take a look:
    Cookie c1 = new Cookie("selectedCatgId", catgId);
    response.addCookie(c1); //here you added a new cookie that has not been sent to the client yet
    RequestDispatcher dispatcher;
    dispatcher = request.getRequestDispatcher("target.jsp"); //Here you called a new JSP page. A server side operation.
    Cookie cookies[] = request.getCookies(); //Here you are reading a cookie sent by the client. But the c1 has not been sent to the client yet. So you didnt get this cookie on the request.

  • Setting the cookies in jsp

    Hi
    Iam trying to add the cookie into local machine.Problems is i written cookie program in cookietest.jsp then i incude this jsp into index.jsp.When iam accessing the index.jsp cookies are not setting But when iam acessing cookietest.jsp cookies are adding.why index.jsp accessing time not adding??please help me how to achive this one.
    below the code snippet
    **********************cookietest.jsp***********************
    <%@ page import="java.util.Date"%>
    <%@ page import="java.net.*"%>
    <%
         Date now = new Date();
         String timestamp = now.toString();
         Cookie cookie = new Cookie ("Venkateswarlu", "ravi");
         cookie.setMaxAge(365 * 24 * 60 * 60);
         response.addCookie(cookie);
    %>
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    </BODY>
    </HTML>
    **************************end*****************************
    ***********************index.jsp***************************
    <jsp:include page="/cookietest.jsp"/>
    Thanks for advace
    Venkatesearlu Ravi

    Actually this is requirment
    I have to add the that cookie code snippet to every
    page.SO what i did is i placed the cookie code
    snippet into footer.jsp.This footer jsp will include
    every page..Here cookie is not adding.
    Is there any solution.I also tried this with JSTL c:import, since the JSTL1.1 spec says that c:import covers many of the shortcomings of jsp:include.
    /p/cookies/include.jsp
    <%@ page import="java.util.Date"%>
    <%@ page import="java.net.*"%>
    <%
    Date now = new Date();
    String timestamp = now.toString();
    Cookie cookie = new Cookie ("Venkateswarlu", "ravi");
    cookie.setMaxAge(365 * 24 * 60 * 60);
    response.addCookie(cookie);
    %>
    /p/cookies/page1.jsp
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <c:import url="/p/cookies/include.jsp"/>
    <html>
    <head><title>Page 1</title></head>
    <body>
    <%request.getCookies();%>
    </body>
    </html>
    /p/cookies/page2.jsp
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <c:import url="/p/cookies/include.jsp"/>
    <html>
    <head><title>Page 2</title></head>
    <body>
    <%request.getCookies();%>
    </body>
    </html>
    But the result is the same as jsp:include as far as setting HTTP Headers (Cookies) is concerned.
    So the conclusion is that you can't really set HTTP headers in include files.
    Then, you can try it with Servlets instead of JSPs. But then, you'll need to call the servlet each time, before every JSP is invoked.
    I don' know how that's done. Probably through Filters
    (a wild guess)
    Message was edited by:
    appy77

  • Deleting a cookie in JSP

    Can anybody help giving me the syantax on how to delete a cookie in a JSP?

    Can anybody help giving me the syantax on how to
    delete a cookie in a JSP?Cookie c = new Coockie('name', '');
    c.setMaxAge(0); /* from API: A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted. */
    response.addCookie(c);
    read a docs...

  • How to find browser is not supporting cookies using jsp/servlet?

    still....... now i develope one session tracking concept in my project using cookies.
    but after implementing my application to some client . Its browser dosen't support cookies.
    so how to avoid this problem before implementing application.

    Are you actually using cookies or you just need to retain session attributes?
    You can use URL rewriting to encode the session id into urls for browsers that do not accept session cookies.
    Check out HttpServletResponse.encodeURL.
    Note you would have to do this for all links/forms in your web app.

  • Setting cookies in JSP

    Hi ,
    I have a form where user enter their e-mial address, now i want to set up a cookie on their browser. I know i can add the cookie using the addCookie() method.
    My doubt is to the addCookie method i have to send cookieName and value, i have to get these for every user using the request.getParameter() method , what we usually set as cookieName and value in the initial form.And i think i have to cretae these as hidden variables?
    Some body suggest me.

    Is there any reason why you want to use cookies instead of session? You can get the user's email address and store it in the session and get it out of the session when you need it. Do something like:
    String emailAddress = (String)session.getAttribute("emailAddress");
    if (emailAddress == null) {
    emailAddress = request.getParameter("<name_of_email_field_in_form>");
    session.setAttribute("emailAddress", emailAddress);
    and whenever you need the emailAddress, it will be in the String variable "emailAddress".

  • I successfully add a cookie, but cannot read the cookie in another jsp page

    Putting cookie*******************************
    page1.jsp
    <%Cookie adam = new Cookie("adam", "adam");
    adam.setMaxAge(3600*365);
    response.addCookie(adam);
    %>
    Reading cookie*********************************
    page2.jsp
    <%String userid = "";
    Cookie[] cookies = request.getCookies();%>
    <%=cookies.length%>
    <%for (int i = 0; i < cookies.length; i++) {
    Cookie aCookie = cookies;
    if (aCookie.getName().equals("adam")==true){
    userid = aCookie.getValue();%>
    <%=userid%>
    <%break;
    }%>
    I checked my cookies and it did drop the cookie.
    cookies.length = 1
    Cookie[0] contains garbage or encrypted data.
    Does anyone know what I am doing wrong

    Hi, are you sure that is not a problem of paths,
    in you page where you get the cookies try
    cookie.getPath() to see from where are you trying to get it, could be different from the path where you set it.
    The documentation of the Cookie class
    (http://java.sun.com/products/servlet/2.2/javadoc/index.html) can help you more.
    I am sure that this is the problem.
    Regards,
    Ionel C.

  • JSP COOKIES HELP

    Hi guys,
    I'm trying to set cookies with JSP. Its a very long String and I end up having this error:
    Aug 3, 2007 4:59:40 PM org.apache.jk.common.MsgAjp cpBytes
    SEVERE: Buffer overflow: buffer.len=8192 pos=102 data=12692
    Aug 3, 2007 4:59:40 PM org.apache.jk.common.MsgAjp cpBytes
    SEVERE: Overflow
    Its buffer overflow... so its there a way to somehow convert or compress that long String so that it can fit in cookies?
    Thanks

    Could you cookkie a reference to a session object - the session objects being serialised and stored in a database (or details to reconstruct the session object) on a DBserver which of course is accessable to all servers.
    This may increase DB traffic but my opinion would be that this is the price you pay for running multiple servers. The sessions or info' about the client must be communicated somehow between the servers so why not use a DBserver? The only other options would be to pipe the sessions between servers, requiring 28 pipes to interconnect 8 servers or (as you are) to store the data with the client which I agree is an abuse of cookies. Secondly, Have you considered the possibility that the client may not accept cookies? The Session API uses cookie but with 'backup' systems for clients that do not accept them.
    Bamkin

  • Cookie handling with using JSP pages

    How can I use cookies in JSP pages.. Can you send me sample codes or explanations ...
    Ergin DEMIREL
    Thanks in advance..

    http://www.google.com/

  • How to disable Format Warning when displaying JSP in Excel under MS-Office

    We have an application running in WebSphere 6.0 container, the application displays jsp data in Excel, it had no problem before MS-Office 2007 was install. However, after MS-Office 2007 is used, following format warning dialog box is always displayed:
    The file you are trying to open, ’Requests[1].xls’, is in a different format than specified by the file extension.
    Verify that the file is not corrupted and is from a trusted source before opening the file.
    The user has to click the "Yes" button before the Excel report can be successfully displayed. This is not acceptable by our production users, and I need your helps to get rid of this dialog box.
    The application uses struts. The Action class retrieves data from database and the data is forward to the result jsp
    in an data object set in an attribute of the session's Request object. The Action class also set the display info, such as the contentType,etc., in session's Response object (please see below for details).
    The result jsp retrieves data from the data object and display in Excel according to the display info provided in the
    session response object.
    To eliminate any possible problem that may be caused by the data, I have simplified the result jsp by removing original
    codes (such as data object forwarded from Action, and Tag Library, etc.), and just hardcoded few data for displaying in Excel, however, the same format warning box still always shows up.
    My Action class set display info as below:
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");
    response.setHeader("content-disposition","attachment; filename=Requests.xls");
    My simplified result jsp is listed below:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <!-- <%@ taglib prefix='c' uri='http://java.sun.com/jstl/core_rt'%> -->
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    <TABLE border="1">
         <TBODY>
         <TR>
         <td><p align='left'>myData1</p></td>
         <td><p align='left'>myData2</p></td>
         <td><p align='left'>myData3</p></td>
         <td><p align='left'>myData4</p></td>
         </TR>
         </TBODY>
    </TABLE>
    </BODY>
    </HTML>
    So, I reduced the result jsp to contain only few hardcoded data, but the format warning always shows up. Is it caused by inconsistency between the MS-Office 2007 browser and the JSP engine in WebSphere 6.0 Web container? Need your help to resolve this problem.
    Thanks in advance.

    That's the caveat of fooling your webbrowser and Excel with a plain HTML page along an Excel content-type and Excel extension.
    Don't do that. That's plain stupid. Provide a real binary Excel file. You can create one using Apache POI HSSF or Andy Khan's JExcelAPI. Alternatively -and more recommended in case of large reports-, just use the CSV format. It's easy to create a CSV file in 20 lines of code and Excel perfectly understands CSV formats. Don't forget to change content-type to CSV.

  • Setting identical cookie names on a response

              WebLogic Server 6.1 SP2 running on NT 4.0 SP6
              We need to use a non-persistent cookie as a persistence mechanism to store sessioninformation
              when a user browser on multiple pages. The cookie may be set multipletimes on
              the same page using the same response (since the request can be sharedby multiple
              jsp's included in the page).I am noticing that when we set multiple cookies with
              identical name on the sameresponse - the most recent cookie which stores the most
              updated information ISN'Tnecessarily the one which get is get set.This functionality
              is critical for our application's session management and becauseof that problem
              we can't have a reliable way to set a cookie multiple times withinthe same page
              (again - essential in our case)Here is a simple test case that contains 2 jsp's
              that demonstrate the problem.You can place them in the web root and invoke the
              first one - set_cookie.jsp.Subsequently invoke second jsp get_cookie.jsp and you
              will see that the most recentset value ISN'T the one that is read from the cookie.Thanks
              in advanceAri [email protected] get cookie code jsp
              follows (apparently can attach only one file)yields the first cookie set and not
              the last one.
              [set_cookie.jsp]
              

              Sorry for the multiple postings (an error)
              Here is the check_cookies.jsp
              TIA
              Ari
              "Ari" <[email protected]> wrote:
              >
              >
              >
              >WebLogic Server 6.1 SP2 running on NT 4.0 SP6
              >
              >We need to use a non-persistent cookie as a persistence mechanism to
              >store sessioninformation
              >when a user browser on multiple pages. The cookie may be set multipletimes
              >on
              >the same page using the same response (since the request can be sharedby
              >multiple
              >jsp's included in the page).I am noticing that when we set multiple cookies
              >with
              >identical name on the sameresponse - the most recent cookie which stores
              >the most
              >updated information ISN'Tnecessarily the one which get is get set.This
              >functionality
              >is critical for our application's session management and becauseof that
              >problem
              >we can't have a reliable way to set a cookie multiple times withinthe
              >same page
              >(again - essential in our case)Here is a simple test case that contains
              >2 jsp's
              >that demonstrate the problem.You can place them in the web root and invoke
              >the
              >first one - set_cookie.jsp.Subsequently invoke second jsp get_cookie.jsp
              >and you
              >will see that the most recentset value ISN'T the one that is read from
              >the cookie.Thanks
              >in advanceAri [email protected] get cookie
              >code jsp
              >follows (apparently can attach only one file)yields the first cookie
              >set and not
              >the last one.
              [check_cookie.jsp]
              

  • Setting identical cookies on a response

              WebLogic Server 6.1 SP2 running on NT 4.0 SP6
              We need to use a non-persistent cookie as a persistence mechanism to store session
              information when a user browser on multiple pages. The cookie may be set multiple
              times on the same page using the same response (since the request can be shared
              by multiple jsp's included in the page).
              I am noticing that when we set multiple cookies with identical name on the same
              response - the most recent cookie which stores the most updated information ISN'T
              necessarily the one which get is get set.
              This functionality is critical for our application's session management and because
              of that problem we can't have a reliable way to set a cookie multiple times within
              the same page (again - essential in our case)
              Here is a simple test case that contains 2 jsp's that demonstrate the problem.
              You can place them in the web root and invoke the first one - set_cookie.jsp.
              Subsequently invoke second jsp get_cookie.jsp and you will see that the most recent
              set value ISN'T the one that is read from the cookie.
              Thanks in advance
              Ari Senator
              [email protected]
              203-614-3209
              The get cookie code jsp follows (apparently can attach only one file)
              yields the first cookie set and not the last one.
              <%
              String cookieValue ="";
              Cookie[] cookies = null;
              cookies = request.getCookies();
              if (cookies != null && cookies.length > 0) {
                             System.out.println("cookies.length: " + cookies.length);               
                   for (int i = 0; i < cookies.length; i++) {
                        if (cookies .getName ().equals ("data")) {
                                  cookieValue = cookies[i].getValue();
              %>     
              <html>
              <body>
              <%="cookie value " + cookieValue %>
              </body>
              </html>
              [set_cookie.jsp]

    This issue has been resolved. Please log a support case if you need a fix
              for this issue.
              thanks,
              Patrick
              "Ari" <[email protected]> wrote in message
              news:[email protected]...
              >
              > I did.
              > Last Tuesday (03/26 )
              > Here is the case number
              > CASE_ID_NUM: 315955 CR072557
              >
              > Hopefully they will respond quickly ...
              >
              > Rajesh Mirchandani <[email protected]> wrote:
              > >
              > >This looks like a bug. Contact [email protected].
              > >
              > >[email protected] wrote:
              > >
              > >> Ah - you are right. It looks like response.addCookie() doesn't check
              > >the
              > >> cookie name etc at all and sends back all cookies added:
              > >>
              > >> <%
              > >> response.addCookie(new Cookie("foo", "123"));
              > >> response.addCookie(new Cookie("foo", "345"));
              > >> %>
              > >>
              > >> produces:
              > >>
              > >> HTTP/1.0 200 OK
              > >> Date: Tue, 26 Mar 2002 22:40:21 GMT
              > >> Server: WebLogic WebLogic Server 6.1 SP2 12/18/2001 11:13:46 #154529
              > >> Content-Length: 0
              > >> Content-Type: text/html
              > >> Set-Cookie: foo=345
              > >> Set-Cookie: foo=123
              > >> Set-Cookie:
              JSESSIONID=8g4bo2abPrRKsrQjVoNJNIcQ36lnsZgIDVPdg92qzY5EI3Bs52za!1900939556!-
              1062731153!7001!7002;
              > >path=/
              > >> Connection: Close
              > >>
              > >> and I guess that browser uses the last "foo" cookie value - 123.
              > >>
              > >> Resin does the same thing, but sends cookies back in the order they
              > >were
              > >> added:
              > >>
              > >> HTTP/1.0 200 OK
              > >> Server: Resin/2.0.5
              > >> Set-Cookie: foo=123
              > >> Set-Cookie: foo=345
              > >> ...
              > >>
              > >> Ari <[email protected]> wrote:
              > >>
              > >> > The buffer size isn't the issue (it's set by us to 64K)
              > >> > I also know (checked) that the response wasn't committed at any
              stage.
              > >> > <[email protected]> wrote:
              > >> >>Did you try increasing jsp buffer size? When your page(pages) write
              > >> >>> 8k (default buffer size), response is being committed (send to
              > >the
              > >> >>client) and cookies are send at this point.
              > >> >>
              > >> >>Ari <[email protected]> wrote:
              > >> >>> This is a multi-part message in MIME format.
              > >> >>
              > >> >>> ---=_newsgroups3ca0dfba
              > >> >>> Content-Type: text/plain
              > >> >>> Content-Transfer-Encoding: 7bit
              > >> >>
              > >> >>
              > >> >>> WebLogic Server 6.1 SP2 running on NT 4.0 SP6
              > >> >>> We need to use a non-persistent cookie as a persistence mechanism
              > >to
              > >> >>store session
              > >> >>> information when a user browser on multiple pages. The cookie may
              > >be
              > >> >>set multiple
              > >> >>> times on the same page using the same response (since the request
              > >can
              > >> >>be shared
              > >> >>
              > >> >>> by multiple jsp's included in the page).
              > >> >>
              > >> >>> I am noticing that when we set multiple cookies with identical
              > >name
              > >> >>on the same
              > >> >>> response - the most recent cookie which stores the most updated
              > >information
              > >> >>ISN'T
              > >> >>> necessarily the one which get is get set.
              > >> >>> This functionality is critical for our application's session
              management
              > >> >>and because
              > >> >>> of that problem we can't have a reliable way to set a cookie
              multiple
              > >> >>times within
              > >> >>> the same page (again - essential in our case)
              > >> >>
              > >> >>> Here is a simple test case that contains 2 jsp's that demonstrate
              > >the
              > >> >>problem.
              > >> >>> You can place them in the web root and invoke the first one -
              set_cookie.jsp.
              > >> >>> Subsequently invoke second jsp get_cookie.jsp and you will see
              > >that
              > >> >>the most recent
              > >> >>> set value ISN'T the one that is read from the cookie.
              > >> >>
              > >> >>> Thanks in advance
              > >> >>> Ari Senator
              > >> >>
              > >> >>> [email protected]
              > >> >>> 203-614-3209
              > >> >>
              > >> >>> The get cookie code jsp follows (apparently can attach only one
              > >file)
              > >> >>> yields the first cookie set and not the last one.
              > >> >>
              > >> >>> <%
              > >> >>> String cookieValue ="";
              > >> >>> Cookie[] cookies = null;
              > >> >>> cookies = request.getCookies();
              > >> >>> if (cookies != null && cookies.length > 0) {
              > >> >>> System.out.println("cookies.length: " +
              cookies.length);
              > >> >>
              > >> >>> for (int i = 0; i < cookies.length; i++) {
              > >> >>> if (cookies .getName ().equals ("data")) {
              > >> >>> cookieValue = cookies[i].getValue();
              > >> >>> }
              > >> >>> }
              > >> >>> }
              > >> >>
              > >> >>> %>
              > >> >>
              > >> >>> <html>
              > >> >>> <body>
              > >> >>> <%="cookie value " + cookieValue %>
              > >> >>> </body>
              > >> >>> </html>
              > >> >>> ---=_newsgroups3ca0dfba
              > >> >>> Content-Type: application/octet-stream;
              name="D:\dev\xp3\src\webroot\set_cookie.jsp"
              > >> >>> Content-Transfer-Encoding: base64
              > >> >>> Content-Disposition: attachment; filename="set_cookie.jsp"
              > >> >>
              > >> >>> DQo8JQ0KQ29va2llIG15Q29va2llOw0KbXlDb29raWUgPSBuZXcgQ29va2ll
              > >> >>> KCJkYXRhIiwiZmlyc3QiKTsNCm15Q29va2llLnNldFZlcnNpb24oMSk7DQpy
              > >> >>> ZXNwb25zZS5hZGRDb29raWUobXlDb29raWUpOw0KDQovLyAuLi4gcHJvY2Vz
              > >> >>> c2luZw0KDQoNCm15Q29va2llID0gbmV3IENvb2tpZSgiZGF0YSIsInNlY29u
              > >> >>> ZCIpOw0KbXlDb29raWUuc2V0VmVyc2lvbigxKTsNCnJlc3BvbnNlLmFkZENv
              > >> >>> b2tpZShteUNvb2tpZSk7DQoNCi8vIC4uLiBwcm9jZXNzaW5nDQoNCm15Q29v
              > >> >>> a2llID0gbmV3IENvb2tpZSgiZGF0YSIsInRoaXJkIik7DQpteUNvb2tpZS5z
              > >> >>> ZXRWZXJzaW9uKDEpOw0KcmVzcG9uc2UuYWRkQ29va2llKG15Q29va2llKTsN
              > >> >>> Cg0KDQolPg0KDQoJDQo8aHRtbD4NCg0KPGJvZHk+DQpzZXR0aW5nLi4NCjwv
              > >> >>> Ym9keT4NCjwvaHRtbD4=
              > >> >>
              > >> >>> ---=_newsgroups3ca0dfba--
              > >> >>
              > >
              > >--
              > >Rajesh Mirchandani
              > >Developer Relations Engineer
              > >BEA Support
              > >
              > >
              >

  • Not able to set cookie domain ???

    Hi All,
    I am not able to set cookie domain in my webapp(WebApp.mydomain.com).
    My sample code is given below, my webapp name is WebApp.mydomain.com, this has got two jsp pages, one for creating cookie and other one is for reading the cookie.
    CreateCookie.jsp
        Cookie cookie = new Cookie("id","123");
              cookie.setDomain(".mydomain.com");
              cookie.setPath("/");
              response.addCookie(cookie);ReadCookie.jsp
    Cookie[]cks = request.getCookies();
              for(int i=0;i<cks.length;i++){
           out.print("cookie found.............................   "+cks.getValue());
    Issues:
    1. I am not able to read the cookie, if i set the domain as cookie.setDomain(".mydomain.com"); at cookie. I verified it by commenting the domain setting line.
    2. The reason for setting the domain is, I have another web application "WebApp1.mydomain.com" which is supposed to read this cookie which is created in "WebApp.mydomain.com" application.
    3. Is it possible to access the cookie across the applications as the cookie domain and path are been set. (i.e) From WebApp.mydomain.com to WebApp1.mydomain.com?Please share your inputs :(
    Thanks,
    Sundar

    Hi All,
    Any comment/solutions on this???
    Regards,
    Sundar

  • How to disable client cookie using Servlet code

    Hi All,
              I want to disable the client cookie using JSP or servlet code.Is it possible how I can do it.
              Thanks in Advance .

    Hi,
              first of all, the URL rewriting option (URLRewritingEnabled) in the weblogic.xml must be set to true.
              Now, for all first-timer web requests the BEA WLS always uses URL rewriting in addition to cookies to see wether the browser accepts cookies or not.
              I would try to rip of all of the cookies in the header, then flush the response to force the http header to be written.
              I have never tried it and has no idea if it will work, however the teory behind supports the idea.
              This will not work for toggling session tracking mechanism from a session already established with cookies, the session will be lost if attempted to do this without the URL-rewriting enabled on the page.
              - Anders M.

Maybe you are looking for

  • How to set up a hotspot

    Hi, Using Network Manager, I can set up a hotspot while using wired connection. However, is it possible to set up a hotspot using a wireless connection? It seems OK for Windows. Thanks for advice.

  • WIN XP PRO vs WIN 7 PRO FOR CS5

    I'll be ordering a new "Sandy Bridge"  i72600 computer on Monday. Going from Win XP PRO 32 bit on my current PC, to a 64 bit OS on the new one. I was "set" to go with Win 7 PRO, but somewhat dreading the hassle of transforming to a "new" OS. I prefer

  • I accidentally deleted iPhoto on my mac and it says the the app was downloaded with a different apple id and now i can't get the app back without paying $14.99

    i accidentally deleted iPhoto on my mac and it says the the app was downloaded with a different apple id and now i can't get the app back without paying $14.99

  • IPad taking a long time to recharge

    When iPad battery is down to around 30% or less and I recharge, it takes a long time to recharge. Overnight, it charges maybe 10-15% and the charger itself becomes hot. I understand it should take about 3 hours to recharge to 100%. That's seldom happ

  • How to imlement Sales Planning

    Hi, I will implement the following sales planning scenario in BPC 7.0, NW version: Input sales amount, input price and then automatically calculate the sales volume (sales volume = sales amount * price). Have anybody an Idea how I can implement this