一、 Java获取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;
}
二、获取请求的URL地址
/**
* 获取请求的IP地址
* @return
*/
public String getRequestIpAddress(){
return ServletActionContext.getRequest().getRemoteAddr();
}
三、获取请求的IP地址文章来源:https://www.toymoban.com/news/detail-572613.html
/**
* 获取请求的IP地址
* @return
*/
public String getRequestIpAddress(){
return ServletActionContext.getRequest().getRemoteAddr();
}
四:判断字符串是否能够转换成指定格式的日期文章来源地址https://www.toymoban.com/news/detail-572613.html
/**
* 验证字符串是否能够转换成指定格式的日期
* @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;
}
到了这里,关于Java获取URL地址中传递的参数的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!