1 16 17 package org.springframework.web.servlet.mvc; 18 19 import javax.servlet.RequestDispatcher ; 20 import javax.servlet.ServletException ; 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 24 import org.springframework.beans.factory.BeanNameAware; 25 import org.springframework.web.servlet.ModelAndView; 26 import org.springframework.web.util.WebUtils; 27 28 99 public class ServletForwardingController extends AbstractController implements BeanNameAware { 100 101 private String servletName; 102 103 private String beanName; 104 105 106 111 public void setServletName(String servletName) { 112 this.servletName = servletName; 113 } 114 115 public void setBeanName(String name) { 116 this.beanName = name; 117 if (this.servletName == null) { 118 this.servletName = name; 119 } 120 } 121 122 123 protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) 124 throws Exception { 125 126 RequestDispatcher rd = getServletContext().getNamedDispatcher(this.servletName); 127 if (rd == null) { 128 throw new ServletException ("No servlet with name '" + this.servletName + "' defined in web.xml"); 129 } 130 if (useInclude(request, response)) { 132 rd.include(request, response); 133 if (logger.isDebugEnabled()) { 134 logger.debug("Included servlet [" + this.servletName + 135 "] in ServletForwardingController '" + this.beanName + "'"); 136 } 137 } 138 else { 139 rd.forward(request, response); 140 if (logger.isDebugEnabled()) { 141 logger.debug("Forwarded to servlet [" + this.servletName + 142 "] in ServletForwardingController '" + this.beanName + "'"); 143 } 144 } 145 return null; 146 } 147 148 162 protected boolean useInclude(HttpServletRequest request, HttpServletResponse response) { 163 return (WebUtils.isIncludeRequest(request) || response.isCommitted()); 164 } 165 166 } 167 | Popular Tags |