cn.kduck.core.utils.RequestUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kduck-core Show documentation
Show all versions of kduck-core Show documentation
The core of the K-Duck development framework encompasses all the featured components of the framework.
package cn.kduck.core.utils;
import cn.kduck.core.service.ValueMap;
import javax.servlet.http.HttpServletRequest;
import java.util.Iterator;
import java.util.Map;
public final class RequestUtils {
private RequestUtils() {}
public static ValueMap getParameterMap(HttpServletRequest request) {
if(request == null){
return ValueMap.EMPTY_VALUE_MAP;
}
Map parameterMap = request.getParameterMap();
ValueMap valueMap = new ValueMap();
Iterator keys = parameterMap.keySet().iterator();
while(keys.hasNext()){
String name = keys.next();
String[] v = parameterMap.get(name);
valueMap.put(name,v.length == 1 ? v[0]: v);
}
return valueMap;
}
public static boolean isAjax(HttpServletRequest request){
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
}
}