forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParamUtils.java
More file actions
133 lines (119 loc) · 4.11 KB
/
ParamUtils.java
File metadata and controls
133 lines (119 loc) · 4.11 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.core;
import javax.servlet.http.HttpServletRequest;
import com.jspsmart.upload.Request;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: MR</p>
* @version 1.0
*/
public class ParamUtils {
public static String getParameter(HttpServletRequest request,
String paramName) {
return getParameter(request, paramName, false);
}
//对空字符串进行处理
public static String getParameter(HttpServletRequest request,
String paramName, String defaultStr) {
String temp = request.getParameter(paramName);
if (temp != null) {
if (temp.equals("")) {
return defaultStr;
} else {
return nullToString(temp);
}
} else {
return defaultStr;
}
}
public static String getEscapeHTMLParameter(HttpServletRequest request,
String paramName) {
return nullToString(StringUtils.escapeHTMLTags(ParamUtils.getParameter(
request, paramName, true)));
}
public static String getParameter(HttpServletRequest request,
String paramName, boolean emptyStringsOK) {
String temp = request.getParameter(paramName);
if (temp != null) {
if (temp.equals("") && !emptyStringsOK) {
return "";
} else {
return temp;
}
} else {
return "";
}
}
public static int getIntParameter(HttpServletRequest request,
String paramName, int defaultNum) {
String temp = request.getParameter(paramName);
if (temp != null && !temp.equals("")) {
int num = defaultNum;
try {
num = Integer.parseInt(temp);
} catch (Exception ignored) {}
return num;
} else {
return defaultNum;
}
}
public static int getIntParameter(HttpServletRequest request,
String paramName) {
return getIntParameter(request, paramName, 0);
}
public static String nullToString(String oldString) {
if (oldString == null) {
return "";
}
return oldString;
}
public static String nullToString(String oldString,String defaultValue) {
oldString=nullToString(oldString);
if("".equals(oldString)){
return defaultValue;
}
return oldString;
}
//修改使用的方法
public static String getRequestString(HttpServletRequest request,String s){
s=nullToString(s).trim();
s=ParamUtils.getEscapeHTMLParameter(request, s);
s=StringUtils.toChinese(s);
s=StringUtils.toUnicode(s);
s=StringUtils.StringtoSql(s);
return s;
}
//添加使用的方法
public static String getRequestString(Request request, String s) {
s=nullToString(s).trim();
s=ParamUtils.getEscapeHTMLParameter(request, s);
//转码
// s=StringUtils.toChinese(s);
s=StringUtils.toUnicode(s);
s=StringUtils.StringtoSql(s);
return s;
}
public static String getSqlString(String s){
s=StringUtils.SqltoString(s);
s=StringUtils.toChinese(s);
s=nullToString(s).trim();
return s;
}
public static String getEscapeHTMLParameter(Request request, String s) {
return nullToString(StringUtils.escapeHTMLTags(request.getParameter(s)));
}
public static int getIntParameter(Request request, String s) {
int defaultNum=0;
String temp = request.getParameter(s);
if (temp != null && !temp.equals("")) {
int num = defaultNum;
try {
num = Integer.parseInt(temp);
} catch (Exception ignored) {}
return num;
} else {
return defaultNum;
}
}
}