zoukankan      html  css  js  c++  java
  • java请求参数转换

    public class HttpServletRequestUtil {
    	//转换请求参数
    	public static int getInt(HttpServletRequest request, String name) {
    
    		//整型
    		try {
    			return Integer.decode(request.getParameter(name));
    		} catch (Exception e) {
    			return -1;
    		}
    	}
    
    	public static long getLong(HttpServletRequest request, String name) {
           //长整型
    		try {
    			return Long.valueOf(request.getParameter(name));
    		} catch (Exception e) {
    			return -1;
    		}
    	}
    
    	public static Double getDouble(HttpServletRequest request, String name) {
    
    		try {
    			return Double.valueOf(request.getParameter(name));
    		} catch (Exception e) {
    			return -1d;
    		}
    	}
    
    	public static Boolean getBoolean(HttpServletRequest request, String name) {
    
    		try {
    			return Boolean.valueOf(request.getParameter(name));
    		} catch (Exception e) {
    			return false;
    		}
    	}
    
    	public static String getString(HttpServletRequest request, String name) {
    		try {
    			String result = request.getParameter(name);
    			if (result != null) {
    				result = result.trim();
    			}
    			if ("".equals(result))
    				result = null;
    			return result;
    		} catch (Exception e) {
    			return null;
    		}
    	}
    }
    

      

  • 相关阅读:
    ESP8266简单几步建立服务器
    SVM推导
    标准的最大margin问题
    switch用法
    vecor预分配内存溢出2
    vector预分配空间溢出
    [面试编程题]算法基础-字符移位
    [面试编程题1]构造回文
    一天学完UFLDL
    神经网络中的XOR问题
  • 原文地址:https://www.cnblogs.com/sunliyuan/p/10634705.html
Copyright © 2011-2022 走看看