servlet处理参数的一些操作

import javax.servlet.http.HttpServletRequest;

public final class ParameterUtils {

public static boolean isNumber(String key){
if(key != null && key.length() > 0){
return key.matches("^[0-9]+$");
}else{
return false;
}

}
/**
*
* @param request
* @param key
* @param vs
* @return
*/
public static int getInt(HttpServletRequest request,String key,int vs){
String temp = request.getParameter(key);
int rs = vs;
if(temp != null && isNumber(key)){
rs = Integer.parseInt(temp);
}
return rs;
}

public static String getString(HttpServletRequest request,String key,String vs){
String temp = request.getParameter(key);
String rs = vs;
if(temp != null && !"".equals(temp) ){
rs = temp;
}
return rs;
}


// public static void main(String[] args){
// System.out.println(isNumber(null));
// }
}

你可能感兴趣的:(servlet)