1 16 package dlog4j.util; 17 18 import javax.servlet.ServletRequest ; 19 import javax.servlet.http.HttpServletRequest ; 20 21 25 public class RequestUtils { 26 27 public static String getBaseURL(HttpServletRequest req){ 28 String url = req.getRequestURL().toString(); 29 String uri = req.getRequestURI(); 30 String context = req.getContextPath(); 31 int idx = url.indexOf(uri); 32 return (idx==-1)?url:url.substring(0,idx) + context; 33 } 34 41 public static int getIntParameter(ServletRequest req, String param, int defValue) { 42 int value = defValue; 43 try { 44 value = Integer.parseInt(req.getParameter(param)); 45 }catch(Exception e) {} 46 return value; 47 } 48 49 public static void main(String [] args) { 50 } 51 } 52 | Popular Tags |