| Servlets.java |
1 // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
2 // Distributable under LGPL license. See terms of license at gnu.org.
3
4 package nl.justobjects.pushlet.util;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9
10/**
11 * Servlet utilities.
12 *
13 * @author Just van den Broecke - Just Objects ©
14 * @version $Id: Servlets.java,v 1.2 2007/11/23 21:10:17 justb Exp $
15 */
16public class Servlets {
17
18 /**
19 * Get parameter; if not set or empty return null.
20 */
21 public static String getParameter(HttpServletRequest aRequest, String aName) {
22 return getParameter(aRequest, aName, null);
23 }
24
25 /**
26 * Get parameter; if not set or empty return specified default value.
27 */
28 public static String getParameter(HttpServletRequest aRequest, String aName, String aDefault) {
29 String value = aRequest.getParameter(aName);
30 if (value == null || value.length() == 0) {
31 value = aDefault;
32 }
33 return value;
34 }
35
36 /**
37 * Set HTTP headers to prevent caching.
38 */
39 public static void setNoCacheHeaders(HttpServletResponse aResponse) {
40 // Set to expire far in the past.
41 aResponse.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
42
43 // Set standard HTTP/1.1 no-cache headers.
44 aResponse.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
45
46 // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
47 aResponse.addHeader("Cache-Control", "post-check=0, pre-check=0");
48
49 // Set standard HTTP/1.0 no-cache header.
50 aResponse.setHeader("Pragma", "no-cache");
51
52 }
53
54}
55
56/*
57 * $Log: Servlets.java,v $
58 * Revision 1.2 2007/11/23 21:10:17 justb
59 * add hooks for custom logging (you can override DefaultLogger in pushlet.properties)
60 *
61 * Revision 1.1 2004/09/20 22:01:40 justb
62 * more changes for new protocol
63 *
64 *
65 */
66
67
68| Servlets.java |