forked from wujun728/jun_java_plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAjaxUtil.java
More file actions
47 lines (41 loc) · 1.34 KB
/
Copy pathAjaxUtil.java
File metadata and controls
47 lines (41 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package org.myframework.util;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class AjaxUtil {
private static Log log = LogFactory.getLog(AjaxUtil.class);
/**
* 从request中获取所有查询参数值并以&abc=123的方式返回
* @param request
* @return String
*/
public static String getUrlParam(HttpServletRequest request) {
StringBuffer urlParam = new StringBuffer("");
for (Enumeration elements = request.getParameterNames(); elements
.hasMoreElements();) {
String key = (String) elements.nextElement();
String value = request.getParameter(key);
urlParam.append("&" + key + "=" + value);
}
log.debug(urlParam.toString());
return urlParam.toString();
}
/**
* 从request中获取所有查询参数值并以JSON数组的方式返回
* @param request
* @return String
*/
public static String getJsonArray(HttpServletRequest request) {
StringBuffer urlParam = new StringBuffer("[");
for (Enumeration elements = request.getParameterNames(); elements
.hasMoreElements();) {
String key = (String) elements.nextElement();
String value = request.getParameter(key);
urlParam.append("{name:'" + key + "', value:'" + value + "'}");
}
urlParam.append("]");
log.debug(urlParam.toString());
return urlParam.toString();
}
}