1 17 18 package org.apache.geronimo.console.servlet; 19 20 import java.io.IOException ; 21 22 import javax.servlet.RequestDispatcher ; 23 import javax.servlet.ServletConfig ; 24 import javax.servlet.ServletContext ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.UnavailableException ; 27 import javax.servlet.http.HttpServlet ; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 31 37 public class ContextForwardServlet extends HttpServlet { 38 39 public static final String CONTEXT_PATH = "context-path"; 41 public static final String SERVLET_PATH = "servlet-path"; 43 44 private ServletContext forwardContext; 45 private String servletPath; 46 47 public void init(ServletConfig config) throws ServletException { 48 super.init(config); 49 String contextPath = config.getInitParameter(CONTEXT_PATH); 50 servletPath = config.getInitParameter(SERVLET_PATH); 51 if (contextPath == null || servletPath == null) { 52 throw new UnavailableException ("context-path and servlet-path " + 53 "must be provided as configuration parameters"); 54 } 55 forwardContext = getServletContext().getContext(contextPath); 56 } 57 58 public void doGet(HttpServletRequest req, HttpServletResponse resp) 59 throws ServletException , IOException { 60 doPost(req, resp); 61 } 62 63 public void doPost(HttpServletRequest req, HttpServletResponse resp) 64 throws ServletException , IOException { 65 String dispatchURI = servletPath + (req.getPathInfo() == null ? "" : req.getPathInfo()); 66 String queryString = req.getQueryString(); 67 if (queryString != null) { 68 dispatchURI += "?" + queryString; 69 } 70 RequestDispatcher dispatcher = forwardContext.getRequestDispatcher(dispatchURI); 71 dispatcher.forward(req, resp); 72 } 73 } 74 | Popular Tags |