1 5 package com.opensymphony.webwork.dispatcher; 6 7 import com.opensymphony.webwork.ServletActionContext; 8 import com.opensymphony.webwork.dispatcher.mapper.ActionMapperFactory; 9 import com.opensymphony.xwork.ActionInvocation; 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 13 import javax.servlet.http.HttpServletRequest ; 14 import javax.servlet.http.HttpServletResponse ; 15 16 17 24 public class ServletRedirectResult extends WebWorkResultSupport { 25 27 private static final Log log = LogFactory.getLog(ServletRedirectResult.class); 28 29 31 protected boolean prependServletContext = true; 32 33 35 41 public void setPrependServletContext(boolean prependServletContext) { 42 this.prependServletContext = prependServletContext; 43 } 44 45 52 protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { 53 HttpServletRequest request = ServletActionContext.getRequest(); 54 HttpServletResponse response = ServletActionContext.getResponse(); 55 56 if (isPathUrl(finalLocation)) { 57 if (!finalLocation.startsWith("/")) { 58 String namespace = ActionMapperFactory.getMapper().getMapping(request).getNamespace(); 59 60 if ((namespace != null) && (namespace.length() > 0)) { 61 finalLocation = namespace + "/" + finalLocation; 62 } else { 63 finalLocation = "/" + finalLocation; 64 } 65 } 66 67 if (prependServletContext && (request.getContextPath() != null) && (request.getContextPath().length() > 0)) { 69 finalLocation = request.getContextPath() + finalLocation; 70 } 71 72 finalLocation = response.encodeRedirectURL(finalLocation); 73 } 74 75 if (log.isDebugEnabled()) { 76 log.debug("Redirecting to finalLocation " + finalLocation); 77 } 78 79 response.sendRedirect(finalLocation); 80 } 81 82 private static boolean isPathUrl(String url) { 83 return (url.indexOf(':') == -1); 87 } 88 } 89 | Popular Tags |