www.pudn.com > 200402121144312230.rar > ParamUtils.java
package net.ijsp.news.util; /** *Title:
*Description:
*Copyright: Copyright (c) 2003
*Company: ijsp.net
* @author ccjsmile * @version 1.0 */ import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; public class ParamUtils { public ParamUtils() { } public static String getString(HttpServletRequest request, String s, String defaultString) throws Exception { String s1 = getString(request, s); if(s1 == null) return defaultString; else return s1; } public static int getInt(HttpServletRequest request, String s, int defaultInt) { int j=0; try { String temp = getString(request, s); if(temp == null) { j = defaultInt; }else{ j = Integer.parseInt(temp); } }catch(NumberFormatException e){ j=0; } return j; } public static long getLong(HttpServletRequest request, String s, long defaultLong) { long l = 0; try { String temp = getString(request, s); if(temp == null){ l = defaultLong; }else{ l = Long.parseLong(temp); } } catch(NumberFormatException e) { l=0; } return l; } private static String getString(HttpServletRequest request, String s) { String temp = null; try { temp = request.getParameter(s).trim(); } catch(Exception exception) { } return temp; } }