在调用的时候把request和response的对象都传入JavaBean
或者在JSP中读取了Cookie之后传给JavaBean,再从JavaBean中返回新的JavaBean
再添加到response中

解决方案 »

  1.   

    javaBean:
    Class aa{
       public getCookie(HttpServletRequest request,
                   HttpServletResponse response){
           ......
       }
    }
    jsp页面:
    new aa().getCookie(request,response);
      

  2.   

    Take this:
     
     /**
         * Returns the specified cookie, or <code>null</code> if the cookie
         * does not exist.
         *
         * @param request The HttpServletRequest object, known as "request" in a
         *      JSP page.
         * @param name the name of the cookie.
         * @return the Cookie object if it exists, otherwise <code>null</code>.
         */
        public static Cookie getCookie(HttpServletRequest request, String name) {
            Cookie cookies[] = request.getCookies();
            // Return null if there are no cookies or the name is invalid.
            if(cookies == null || name == null || name.length() == 0) {
                return null;
            }
            // Otherwise, we  do a linear scan for the cookie.
            for (int i = 0; i < cookies.length; i++) {
                if(cookies[i].getName().equals(name) ) {
                    return cookies[i];
                }
            }
            return null;
        }   
     public static void saveCookie(HttpServletResponse response, String name,
                String value)
        {
            // Save the cookie value for 1 month
            saveCookie(response, name, value, 60*60*24*30);
        }    /**
         * Stores a value in a cookie. This cookie will persist for the amount
         * specified in the <tt>saveTime</tt> parameter.
         *
         * @param request The HttpServletResponse object, known as "response" in a
         *      JSP page.
         * @param name a name to identify the cookie
         * @param value the value to store in the cookie
         * @param saveTime the time (in seconds) this cookie should live
         */
        public static void saveCookie(HttpServletResponse response, String name,
                String value, int saveTime)
        {
            // Check to make sure the new value is not null (appservers like Tomcat
            // 4 blow up if the value is null).
            if (value == null) {
                value = "";
            }
            Cookie cookie = new Cookie(name, value);
            cookie.setMaxAge(saveTime);
            cookie.setPath("/");
            response.addCookie(cookie);
        }
      

  3.   

    不好意思,我现在又碰到了新的问题,我写了一个JavaBean来读写Cookie,但是我不知道怎么将请求发送到我自己写的那个Bean进行处理,谢谢。
      

  4.   

    你得学学Model2的jsp:采用servlet来控制web流程,把javabean 仅作为数据的封装而已。