Last active
December 17, 2015 05:49
-
-
Save thaniaclair/5561196 to your computer and use it in GitHub Desktop.
Recuperador de ação do request.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.servlet.http.HttpServletRequest; | |
import org.apache.commons.lang3.StringUtils; | |
/** | |
* Recupera a ação de um {@link HttpServletRequest}. | |
* @author thania | |
*/ | |
public class ActionRetriever { | |
private HttpServletRequest request; | |
private String url; | |
public ActionRetriever(HttpServletRequest request) { | |
this.request = request; | |
} | |
/** | |
* Recupera a ação atual da requisição, através do {@link HttpServletRequest}. | |
* @return URL de tentativa de redirecionamento. | |
*/ | |
public String getCurrentURL() { | |
String context = request.getContextPath() + "/"; | |
StringBuilder url = new StringBuilder(request.getRequestURI().replace(context, "")); | |
String params = request.getQueryString(); | |
if (StringUtils.isNotBlank(params)) url.append("?").append(params); | |
return url.toString(); | |
} | |
public ActionRetriever setRequest(HttpServletRequest request) { | |
this.request = request; | |
return this; | |
} | |
public String getUrl() { | |
return url; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment