本文整理汇总了Java中javax.servlet.ServletRequest.removeAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRequest.removeAttribute方法的具体用法?Java ServletRequest.removeAttribute怎么用?Java ServletRequest.removeAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.ServletRequest
的用法示例。
在下文中一共展示了ServletRequest.removeAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTimeout
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void onTimeout(AsyncEvent event) throws IOException {
// in this time, maybe:
// 1.invocation in executor's queue
// 2.already executing in executor
// 3.already send response
// to avoid concurrent, must lock request
ServletRequest request = event.getSuppliedRequest();
HttpServletRequestEx requestEx = (HttpServletRequestEx) request.getAttribute(RestConst.REST_REQUEST);
synchronized (requestEx) {
ServletResponse response = event.getAsyncContext().getResponse();
if (!response.isCommitted()) {
LOGGER.error("Rest request timeout, method {}, path {}.", requestEx.getMethod(), requestEx.getRequestURI());
// invocation in executor's queue
response.setContentType(MediaType.APPLICATION_JSON);
// we don't know if developers declared one statusCode in contract
// so we use cse inner statusCode here
((HttpServletResponse) response).setStatus(ExceptionFactory.PRODUCER_INNER_STATUS_CODE);
PrintWriter out = response.getWriter();
out.write(TIMEOUT_MESSAGE);
response.flushBuffer();
}
request.removeAttribute(RestConst.REST_REQUEST);
}
}
示例2: doFilter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* This {@code doFilter} implementation stores a request attribute for
* "already filtered", proceeding without filtering again if the attribute is already
* there.
* @param request the request
* @param response the response
* @param filterChain the filter chain
* @throws ServletException if request is not HTTP request
* @throws IOException in case of I/O operation exception
*/
public final void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
if (!(request instanceof HttpServletRequest)
|| !(response instanceof HttpServletResponse)) {
throw new ServletException(
"OncePerRequestFilter just supports HTTP requests");
}
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
boolean hasAlreadyFilteredAttribute = request
.getAttribute(this.alreadyFilteredAttributeName) != null;
if (hasAlreadyFilteredAttribute) {
// Proceed without invoking this filter...
filterChain.doFilter(request, response);
}
else {
// Do invoke this filter...
request.setAttribute(this.alreadyFilteredAttributeName, Boolean.TRUE);
try {
doFilterInternal(httpRequest, httpResponse, filterChain);
}
finally {
// Remove the "already filtered" request attribute for this request.
request.removeAttribute(this.alreadyFilteredAttributeName);
}
}
}
示例3: doFilter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* This {@code doFilter} implementation stores a request attribute for
* "already filtered", proceeding without filtering again if the
* attribute is already there.
* @see #getAlreadyFilteredAttributeName
* @see #shouldNotFilter
* @see #doFilterInternal
*/
@Override
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
throw new ServletException("OncePerRequestFilter just supports HTTP requests");
}
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
String alreadyFilteredAttributeName = getAlreadyFilteredAttributeName();
boolean hasAlreadyFilteredAttribute = request.getAttribute(alreadyFilteredAttributeName) != null;
if (hasAlreadyFilteredAttribute || skipDispatch(httpRequest) || shouldNotFilter(httpRequest)) {
// Proceed without invoking this filter...
filterChain.doFilter(request, response);
}
else {
// Do invoke this filter...
request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);
try {
doFilterInternal(httpRequest, httpResponse, filterChain);
}
finally {
// Remove the "already filtered" request attribute for this request.
request.removeAttribute(alreadyFilteredAttributeName);
}
}
}
示例4: doFilter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* This {@code doFilter} implementation stores a request attribute for
* "already filtered", proceeding without filtering again if the
* attribute is already there.
*
* @see #getAlreadyFilteredAttributeName
* @see #doFilterInternal
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
String alreadyFilteredAttributeName = getAlreadyFilteredAttributeName();
if (request.getAttribute(alreadyFilteredAttributeName) != null) {
log.trace("Filter '{}' already executed. Proceeding without invoking this filter.", getName());
filterChain.doFilter(request, response);
} else {
if (!isEnabled(request, response)) {
log.debug("Filter '{}' is not enabled for the current request. Proceeding without invoking this filter.",
getName());
filterChain.doFilter(request, response);
} else {
// Do invoke this filter...
log.trace("Filter '{}' not yet executed. Executing now.", getName());
request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);
try {
// TODO Maybe do some checks before cast?
doFilterInternal((HttpServletRequest) request, (HttpServletResponse) response, filterChain);
} finally {
// Once the request has finished, we're done and we don't
// need to mark as 'already filtered' any more.
request.removeAttribute(alreadyFilteredAttributeName);
}
}
}
}
示例5: removeActionDefinition
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Remove Definition stored in jsp context.
* Mainly used by Struts to pass a definition defined in an Action to the forward.
*/
public static void removeActionDefinition(
ServletRequest request,
ComponentDefinition definition) {
request.removeAttribute(ACTION_DEFINITION);
}