ParameterUtil
程序员文章站
2022-06-21 14:50:29
...
获取作用域中的值,放置空指针异常
import javax.servlet.http.HttpServletRequest;
public class ParameterUtil {
//从请求中获取String类型的参数
public static String getString(HttpServletRequest request, String name) {
String param = request.getParameter(name);
if (param == null || param.trim().length() == 0) {
return null;
}
return param.trim();
}
public static Integer getInteger(HttpServletRequest request, String name) {
String param = getString(request, name);
if (param == null) {//没传参数
return null;
}
try {
return Integer.parseInt(param);
} catch (NumberFormatException e) {//如果参数不是数字格式
e.printStackTrace();
}
return null;
}
public static Double getDouble(HttpServletRequest request, String name) {
String param = getString(request, name);
if (param == null) {//没传参数
return null;
}
try {
return Double.parseDouble(param);
} catch (NumberFormatException e) {//如果参数不是数字格式
e.printStackTrace();
}
return null;
}
}
上一篇: js内地身份证号码算法
下一篇: 过滤器Filter
推荐阅读