/Users/lyon/j4p/src/net/server/servlets/RequestUtil.java
|
1 package net.server.servlets;
2
3 import javax.servlet.http.Cookie;
4 import javax.servlet.http.HttpServletRequest;
5 import java.util.Enumeration;
6 import java.util.Vector;
7
8 /**
9 * RequestUtil Class
10 */
11
12 public class RequestUtil {
13
14 /**
15 * Returns the parameters as an array
16 *
17 * @return String[]
18 */
19
20 public static String[] getParmNames(HttpServletRequest request) {
21
22 Vector v = new Vector();
23
24 Enumeration e =
25 request.getParameterNames();
26
27 while (e.hasMoreElements())
28 v.addElement(e.nextElement());
29
30 String s[] = new String[v.size()];
31
32 for (int i = 0; i < s.length; i++)
33 s[i] = (String) v.elementAt(i);
34
35 return s;
36
37 }
38
39 /**
40 * Returns the parameter values as an array
41 *
42 * @return String[]
43 */
44
45 public static String[] getParmValues(String pn[],
46 HttpServletRequest request) {
47
48 String pv[] = new String[pn.length];
49
50 for (int i = 0; i < pn.length; i++)
51 pv[i] = request.getParameter(pn[i]);
52
53 return pv;
54 }
55
56 /**
57 * Returns the cookie value
58 *
59 * @return String cookieValue
60 */
61
62 public static String getCookieValue(Cookie[] cookies, String cookieName) {
63
64 for (int i = 0; i < cookies.length; i++) {
65 Cookie cookie = cookies[i];
66 if (cookieName.equals(cookie.getName()))
67 return (cookie.getValue());
68 }
69
70 return null;
71 }
72
73 /**
74 * Returns the Cookies as an array
75 *
76 * @return Cookie cookie
77 */
78
79 public static Cookie getCookie(Cookie[] cookies, String cookieName) {
80
81 for (int i = 0; i < cookies.length; i++) {
82 Cookie cookie = cookies[i];
83 if (cookieName.equals(cookie.getName()))
84 return cookie;
85 }
86
87 return null;
88 }
89
90 }
91
92