Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java Open Source > Struts
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Struts section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2007, 01:55 AM
Authorized User
 
Join Date: Jul 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to david_marsetty
Default i uanable to get data using Cookie in servlet

i uanble to get the data using Cookie in servlet
this is my ex1 servlet
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.Cookie;

public class Ex1 extends HttpServlet
{
    public void doGet(HttpServletRequest req,HttpServletResponse res)
    {
        try{
            res.setContentType("text/html");
            String name=req.getParameter("name");
            String addr=req.getParameter("addr");
            String age=req.getParameter("age");

            PrintWriter out=res.getWriter();
                out.println("<a href=/Httpsessions/second> Show MyDetails </a>");


            Cookie c0=new Cookie("Customer name",name);
            Cookie c1=new Cookie("Customer addr",addr);
            Cookie c2=new Cookie("Customer age",age);
            res.addCookie(c0);
            res.addCookie(c1);
            res.addCookie(c2);



            }catch(Exception e){}
    }
}


and my secon ex2 servlet


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.Cookie;
public class Ex2 extends HttpServlet
{
    public void doGet(HttpServletRequest req,HttpServletResponse res)
    {
        try{
            res.setContentType("text/html");

         Cookie[] cookies = req.getCookies();
            String name0 = cookies[0].getName();
          String value0 = cookies[0].getValue();

          String name1= cookies[1].getName();
          String value1= cookies[1].getValue();

          String name2= cookies[2].getName();
          String value2= cookies[2].getValue();
          PrintWriter out=res.getWriter();
            out.println("Ex2");
          out.println(name0 + ":" + value0);
          out.println(name1 + ":" + value1);
          out.println(name2 + ":" + value2);
   }catch(Exception e){}
  }
}


if any body help to my qus

M.david
__________________
M.david
 
Old December 13th, 2007, 10:05 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

after creating cookies try setting the path of them using cookieObject.setPath(String path). path value should be the second servlet path.

- Rakesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cookie prv299 ASP.NET 2.0 Professional 3 May 29th, 2008 11:26 AM
Sharing cookie data between virtual directories Crowandazi Classic ASP Components 1 February 21st, 2008 04:11 PM
Cookie Questions Ron Howerton ASP.NET 2.0 Professional 15 November 13th, 2007 10:32 AM
xml file read data from servlet kotaiah J2EE 0 October 15th, 2006 06:37 AM
How do I get a cookie to expire.... elladi Classic ASP Basics 1 November 22nd, 2004 12:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.