| 
68
 | 
     1 <%
 | 
| 
 | 
     2 /*
 | 
| 
 | 
     3 Copyright (c) 2008  Franklin Schmidt <fschmidt@gmail.com>
 | 
| 
 | 
     4 
 | 
| 
 | 
     5 Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
| 
 | 
     6 of this software and associated documentation files (the "Software"), to deal
 | 
| 
 | 
     7 in the Software without restriction, including without limitation the rights
 | 
| 
 | 
     8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
| 
 | 
     9 copies of the Software, and to permit persons to whom the Software is
 | 
| 
 | 
    10 furnished to do so, subject to the following conditions:
 | 
| 
 | 
    11 
 | 
| 
 | 
    12 The above copyright notice and this permission notice shall be included in
 | 
| 
 | 
    13 all copies or substantial portions of the Software.
 | 
| 
 | 
    14 
 | 
| 
 | 
    15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
| 
 | 
    16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
| 
 | 
    17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
| 
 | 
    18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
| 
 | 
    19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
| 
 | 
    20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
| 
 | 
    21 THE SOFTWARE.
 | 
| 
 | 
    22 */
 | 
| 
 | 
    23 
 | 
| 
 | 
    24 package fschmidt.tools.web;
 | 
| 
 | 
    25 
 | 
| 
 | 
    26 import java.io.IOException;
 | 
| 
 | 
    27 import javax.servlet.ServletException;
 | 
| 
 | 
    28 import javax.servlet.ServletOutputStream;
 | 
| 
 | 
    29 import javax.servlet.http.HttpServlet;
 | 
| 
 | 
    30 import javax.servlet.http.HttpServletRequest;
 | 
| 
 | 
    31 import javax.servlet.http.HttpServletResponse;
 | 
| 
 | 
    32 import javax.servlet.http.Cookie;
 | 
| 
 | 
    33 import fschmidt.util.servlet.ServletUtils;
 | 
| 
 | 
    34 
 | 
| 
 | 
    35 
 | 
| 
 | 
    36 public class Cookies extends HttpServlet {
 | 
| 
 | 
    37 
 | 
| 
 | 
    38 	protected void service(HttpServletRequest request,HttpServletResponse response)
 | 
| 
 | 
    39 		throws ServletException, IOException
 | 
| 
 | 
    40 	{
 | 
| 
 | 
    41 		ServletOutputStream out = response.getOutputStream();
 | 
| 
 | 
    42 		response.setHeader("cache-control","no-cache");
 | 
| 
 | 
    43 		%>
 | 
| 
 | 
    44 		<html>
 | 
| 
 | 
    45 		<head>
 | 
| 
 | 
    46 		<title>cookies</title>
 | 
| 
 | 
    47 		</head>
 | 
| 
 | 
    48 		<body>
 | 
| 
 | 
    49 		<%
 | 
| 
 | 
    50 		Cookie[] cookies = request.getCookies();
 | 
| 
 | 
    51 		if( cookies == null ) {
 | 
| 
 | 
    52 			%>
 | 
| 
 | 
    53 			no cookies
 | 
| 
 | 
    54 			<%
 | 
| 
 | 
    55 		} else {
 | 
| 
 | 
    56 			%>
 | 
| 
 | 
    57 			<script>
 | 
| 
 | 
    58 			document.write("<p>document.cookie = "+document.cookie);
 | 
| 
 | 
    59 			</script>
 | 
| 
 | 
    60 			<%
 | 
| 
 | 
    61 			for( int i=0; i<cookies.length; i++ ) {
 | 
| 
 | 
    62 				Cookie cookie = cookies[i];
 | 
| 
 | 
    63 				String name = cookie.getName();
 | 
| 
 | 
    64 				%>
 | 
| 
 | 
    65 				<p><%=name%> = <%=cookie.getValue()%>
 | 
| 
 | 
    66 				<%
 | 
| 
 | 
    67 				try {
 | 
| 
 | 
    68 					%>
 | 
| 
 | 
    69 					-> <%=ServletUtils.getCookieValue(request,name)%>
 | 
| 
 | 
    70 					<%
 | 
| 
 | 
    71 				} catch(RuntimeException e) {}
 | 
| 
 | 
    72 			}
 | 
| 
 | 
    73 		}
 | 
| 
 | 
    74 		%>
 | 
| 
 | 
    75 		</body>
 | 
| 
 | 
    76 		</html>
 | 
| 
 | 
    77 		<%
 | 
| 
 | 
    78 	}
 | 
| 
 | 
    79 }
 | 
| 
 | 
    80 %>
 |