Skip to content

Instantly share code, notes, and snippets.

@thaniaclair
Last active December 17, 2015 05:49
Show Gist options
  • Save thaniaclair/5561196 to your computer and use it in GitHub Desktop.
Save thaniaclair/5561196 to your computer and use it in GitHub Desktop.
Recuperador de ação do request.
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