Observations :
a) The value of the res variable is null, hence calling the setCookie method
is throwing an exception and hence no cookie is being set.
b) The reason you are successfully able to use the getProperty method in the
other Jsp is because your abean variable has a session scope. If you change
the scope to page, the result would be different.
Hope this helps.
Have a nice day.
With regards,
Sachin S. Khanna.
www.emailanorder.com

----- Original Message -----
From: anurag dewan <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 13, 2001 4:55 PM
Subject: cookie problem...in JSP


> hi,
> i am trying to set a cookie using Jsps and
> beans......my code is this
> *****jsp page*******
> <%@ page import="anurag.Example1" %>
> <jsp:useBean id="abean" scope="session"
> class="anurag.Example1" />
> <jsp:setProperty name="abean"  property="*" />
> <jsp:forward page="test2.jsp" />
> with html...
> *****bean***************
> package anurag;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.io.*;
> public class Example1{
> private String username;
> HttpServletResponse res;
> HttpServletRequest req;
> public Example1(){
> username=null;
> }
> public void setUsername(String name){
> username=name;
> res.addCookie(new Cookie("session_id",username));
> }
> public String getUsername() {
> Cookie[] cookies = req.getCookies();
>   if (cookies != null)
>   {
>     for(int i=0;i < cookies.length;i++)
>     {
>         String name=cookies[i].getName();
>          return name;
>        }
> }
> return  username;
> }
> }
> ******jsp page*******
> <%@ page import="anurag.Example1" %>
> <jsp:useBean id="abean" scope="session"
> class="anurag.Example1" />
> <jsp:getProperty name="abean" property="username" />!
> with html....
>
> the final page is displaying only the "username" not
> he name of the cookies......
> please help
> thanks
> -anurag
>
> ____________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
> or your free @yahoo.ie address at http://mail.yahoo.ie
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to