1 64 65 package com.jcorporate.expresso.core.jsdkapi; 66 67 import com.jcorporate.expresso.core.misc.StringUtil; 68 import org.apache.log4j.Logger; 69 70 import javax.servlet.RequestDispatcher ; 71 import javax.servlet.ServletException ; 72 import javax.servlet.http.HttpServletRequest ; 73 import javax.servlet.http.HttpServletResponse ; 74 import java.io.IOException ; 75 76 77 86 public class GenericDispatcher { 87 private static Logger log = Logger.getLogger(GenericDispatcher.class); 88 89 92 public GenericDispatcher() { 93 } 94 95 96 107 public static void forward(HttpServletRequest req, HttpServletResponse res, 108 String URL) 109 throws ServletException , IOException { 110 StringUtil.assertNotBlank(URL, "URL to forward to may not be blank"); 111 112 RequestDispatcher rd = req.getRequestDispatcher(URL); 114 115 if (rd == null) { 116 throw new ServletException ("Request dispatcher was null - cannot forward to URL '" + 117 URL + "'"); 118 } 119 if (log.isDebugEnabled()) { 120 log.debug("Forwarding to '" + URL + "'"); 121 } 122 123 rd.forward(req, res); 124 } 125 126 127 128 139 public static void include(HttpServletRequest req, HttpServletResponse res, 140 String URL) 141 throws ServletException , IOException { 142 StringUtil.assertNotBlank(URL, "URL to include may not be blank"); 143 144 RequestDispatcher rd = req.getRequestDispatcher(URL); 146 147 if (rd == null) { 148 throw new ServletException ("Request dispatcher was null - cannot include URL '" + 149 URL + "'"); 150 } 151 if (log.isDebugEnabled()) { 152 log.debug("Including '" + URL + "'"); 153 } 154 155 rd.include(req, res); 156 } 157 158 159 160 167 public static String getContextPath(HttpServletRequest req) { 168 return req.getContextPath(); 169 } 170 171 } 172 | Popular Tags |