Wrox Programmer Forums
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets 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 22nd, 2006, 10:54 AM
Authorized User
 
Join Date: Aug 2005
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default cookies problem

hi ... there iz some problem in this code, i m not getting all the cookies ... can anybody point out my mistake

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class CookieDemo extends HttpServlet
{
    public void service(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
    {
        String bookname;
        res.setContentType("text/html");
        PrintWriter p=res.getWriter();
        bookname=req.getParameter("bookname");
        if(bookname!=null && bookname.length()>0)
        {
            Cookie cookie=new Cookie("book",bookname);
            res.addCookie(cookie);
        }
        Cookie[] cookies=req.getCookies();
        if(cookies.length>0)
        {
            p.println("[list]");
            for(int i=0;i<cookies.length;i++)
            {
                bookname=cookies[i].getValue();
                p.println("<li>"+bookname+"</li>");
            }
            p.println("</ul>");
        }
        p.println("<form action='CookieDemo'>");
        p.println("Enter Book Name: <input type='text' name='bookname'>");
        p.println("<input type='submit' value='Add Book'>");
        p.println("</form>");
    }
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with cookies khb3283 ASP.NET 2.0 Basics 1 October 1st, 2008 11:11 AM
Cookies Problem dparsons ASP.NET 1.0 and 1.1 Professional 0 November 28th, 2006 01:47 PM
Problem with using cookies JSB Beginning PHP 0 November 25th, 2005 11:58 AM
Problem with cookies :( Varg_88 Classic ASP Databases 2 December 13th, 2004 11:34 AM





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