1 16 17 package org.springframework.web.servlet.view; 18 19 import java.util.Map ; 20 21 import javax.servlet.RequestDispatcher ; 22 import javax.servlet.ServletException ; 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 26 import org.springframework.web.util.WebUtils; 27 28 62 public class InternalResourceView extends AbstractUrlBasedView { 63 64 private boolean alwaysInclude = false; 65 66 67 72 public InternalResourceView() { 73 } 74 75 80 public InternalResourceView(String url) { 81 super(url); 82 } 83 84 89 public InternalResourceView(String url, boolean alwaysInclude) { 90 super(url); 91 this.alwaysInclude = alwaysInclude; 92 } 93 94 95 103 public void setAlwaysInclude(boolean alwaysInclude) { 104 this.alwaysInclude = alwaysInclude; 105 } 106 107 108 112 protected void renderMergedOutputModel( 113 Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { 114 115 exposeModelAsRequestAttributes(model, request); 117 118 exposeHelpers(request); 120 121 String dispatcherPath = prepareForRendering(request, response); 123 124 RequestDispatcher rd = request.getRequestDispatcher(dispatcherPath); 127 if (rd == null) { 128 throw new ServletException ( 129 "Could not get RequestDispatcher for [" + getUrl() + "]: check that this file exists within your WAR"); 130 } 131 132 if (useInclude(request, response)) { 134 rd.include(request, response); 135 if (logger.isDebugEnabled()) { 136 logger.debug("Included resource [" + getUrl() + "] in InternalResourceView '" + getBeanName() + "'"); 137 } 138 } 139 140 else { 141 exposeForwardRequestAttributes(request); 142 rd.forward(request, response); 143 if (logger.isDebugEnabled()) { 144 logger.debug("Forwarded to resource [" + getUrl() + "] in InternalResourceView '" + getBeanName() + "'"); 145 } 146 } 147 } 148 149 161 protected void exposeHelpers(HttpServletRequest request) throws Exception { 162 } 163 164 177 protected String prepareForRendering(HttpServletRequest request, HttpServletResponse response) 178 throws Exception { 179 180 return getUrl(); 181 } 182 183 197 protected boolean useInclude(HttpServletRequest request, HttpServletResponse response) { 198 return (this.alwaysInclude || WebUtils.isIncludeRequest(request) || response.isCommitted()); 199 } 200 201 209 protected void exposeForwardRequestAttributes(HttpServletRequest request) { 210 WebUtils.exposeForwardRequestAttributes(request); 211 } 212 213 } 214 | Popular Tags |