All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.kduck.core.utils.RequestUtils Maven / Gradle / Ivy

Go to download

The core of the K-Duck development framework encompasses all the featured components of the framework.

There is a newer version: 2.0.0
Show newest version
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"));
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy