Someone else reported the problem already. You are calling a method in a
bean but the response is never set in the bean, therefore when you access
your RES variable, its null. Also, why do you want to set a cookie? Every
engine does this for you automatically unless you have a .92 JSP engine or
earlier. Sessions are automatically handled for you, so there is never a
need to set a cookie with "session_id". FYI, "jsessionid" is the Standard
cookie name to be used to make your application work across
vendors..starting in Servlet 2.2. Don't worry about sessions. What vendor
are you using (name/version)? I am pretty sure it will do automatic session
cookie handling for you.

> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of anurag dewan
> Sent: Tuesday, February 13, 2001 3:25 AM
> To: [EMAIL PROTECTED]
> 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