| phillip.s.powell@gmail.com 2006-01-24, 7:06 pm |
| Looks a lot simpler than what I came up with, but I'm notorious for
coming up with the most complex solution to things and having to have
others make it simpler for me as I never think of it myself *sigh*
However, I do have one question: Why do you have response.setHeader()
embedded within the HTML code? In PHP that would throw some nasty
HTTP-related warnings and potentially break the page as you are
changing the headers after HTML display?
Phil
James Westby wrote:
> phillip.s.powell@gmail.com wrote:
> [snip]
>
> How's this code. One import, no second request, no "scraping", no
> javax.servlet.http.Cookie, no messing.
>
> <HTML><HEAD><TITLE>TEST</TITLE></HEAD><BODY>
>
> <%@ page import="java.util.Enumeration" %>
>
> Cookies: <% Enumeration e = request.getHeaders("Cookie");
> while (e.hasMoreElements()) {
> String cookie = (String)e.nextElement();
> int index = cookie.indexOf("=");
> if (index > -1) {
> out.println("Name:
> " cookie.substring(0,index) "<br>");
> out.println("Value:
> " cookie.substring(index 1) "<br><br
> } else {
> out.println("Error<br>");
> }
> }
> %>
>
> <% response.setHeader("Set-Cookie", "name=Bob"); %>
>
> </BODY></HTML>
>
> The first load of the page will show just Cookie:
>
> The second should show the name value pairs of the cookie that was set
> the first time.
>
> Considerably less code than you were trying to write, and no headaches.
>
>
> James
|