1. Java obtient les paramètres passés dans l'adresse URL
/**
* 获取URL中的参数名和参数值的Map集合
* @param url
* @return
*/
private Map<String, String> getUrlPramNameAndValue(String url){
String regEx="(\\?|&+)(.+?)=([^&]*)";//匹配参数名和参数值的正则表达式
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(url);
// LinkedHashMap是有序的Map集合,遍历时会按照加入的顺序遍历输出
Map<String, String> paramMap = new LinkedHashMap<String, String>();
while(m.find()){
String paramName = m.group(2);//获取参数名
String paramVal=m.group(3);//获取参数值
paramMap.put(paramName, paramVal);
}
return paramMap;
}
2. Obtenir l'adresse URL de la requête
/**
* 获取请求的IP地址
* @return
*/
public String getRequestIpAddress(){
return ServletActionContext.getRequest().getRemoteAddr();
}
3. Obtenir l'adresse IP demandée
/**
* 获取请求的IP地址
* @return
*/
public String getRequestIpAddress(){
return ServletActionContext.getRequest().getRemoteAddr();
}
Quatre : déterminez si la chaîne peut être convertie en une date dans le format spécifié
/**
* 验证字符串是否能够转换成指定格式的日期
* @param str
* @return date
*/
public static boolean isValidDate(String str ,String formater) {
boolean convertSuccess=true;
SimpleDateFormat format = new SimpleDateFormat(formater);
try {
format.setLenient(false);
format.parse(str);
} catch (ParseException e) {
// e.printStackTrace();
//如果throw java.text.ParseException或者NullPointerException,就说明格式不对
convertSuccess=false;
}
return convertSuccess;
}