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; } } }