<%! // ################################################################# // // Jeroen Pulles, 2002 // // This JSP will add a cookie header to a transparant image. // // The array below is the binary for a 5x5 transparant GIF image. // The accompanying BinaryArrayPrinter class writes the // similar array to the command line. // // Be careful not to add any characters (including spaces) outside // the < % % >. // // The cookie specification // http://www.ietf.org/rfc/rfc2109.txt // // ################################################################# // transparant GIF 5x5 pixels: int[] bytes = new int[]{ 71, 73, 70, 56, 57, 97, 5, 0, 5, 0, 128, 0, 0, 255, 255, 255, 0, 0, 0, 33, 249, 4, 1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 5, 0, 5, 0, 0, 2, 4, 132, 143, 169, 88, 0, 59, }; void printarray(JspWriter out) throws IOException { for (int i = 0; i < bytes.length; i++) { out.write(bytes[i]); } } %><% // Create a Cookie object with your name-value pair that you want to store: Cookie c = new Cookie("MYNAME", "myvalue"); // Makes sure all pages can see this cookie; // You want to be more specific than this to help caching: c.setPath("/"); // Store the cookie for a week (in seconds): c.setMaxAge(604800); response.addCookie(c); response.setContentType("image/gif"); printarray(out); %>