本文整理汇总了Java中javax.servlet.ServletRequest.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRequest.getAttribute方法的具体用法?Java ServletRequest.getAttribute怎么用?Java ServletRequest.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.ServletRequest
的用法示例。
在下文中一共展示了ServletRequest.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setRequest
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Set the request that we are wrapping.
*
* @param request The new wrapped request
*/
@Override
public void setRequest(ServletRequest request) {
super.setRequest(request);
// Initialize the attributes for this request
synchronized (attributes) {
attributes.clear();
Enumeration<String> names = request.getAttributeNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
Object value = request.getAttribute(name);
attributes.put(name, value);
}
}
}
示例2: setRequest
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Set the request that we are wrapping.
*
* @param request The new wrapped request
*/
public void setRequest(ServletRequest request) {
super.setRequest(request);
// Initialize the attributes for this request
synchronized (attributes) {
attributes.clear();
Enumeration names = request.getAttributeNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
Object value = request.getAttribute(name);
attributes.put(name, value);
}
}
}
示例3: processRequest
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Prepare the request based on the filter configuration.
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param state The RD state
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
private void processRequest(ServletRequest request,
ServletResponse response,
State state)
throws IOException, ServletException {
DispatcherType disInt = (DispatcherType) request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
if (disInt != null) {
boolean doInvoke = true;
if (context.getFireRequestListenersOnForwards() &&
!context.fireRequestInitEvent(request)) {
doInvoke = false;
}
if (doInvoke) {
if (disInt != DispatcherType.ERROR) {
state.outerRequest.setAttribute(
Globals.DISPATCHER_REQUEST_PATH_ATTR,
getCombinedPath());
state.outerRequest.setAttribute(
Globals.DISPATCHER_TYPE_ATTR,
DispatcherType.FORWARD);
invoke(state.outerRequest, response, state);
} else {
invoke(state.outerRequest, response, state);
}
if (context.getFireRequestListenersOnForwards()) {
context.fireRequestDestroyEvent(request);
}
}
}
}
示例4: invoke
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Invoke the next Valve in the sequence. When the invoke returns, check
* the response state, and output an error report is necessary.
*
* @param request The servlet request to be processed
* @param response The servlet response to be created
* @param context The valve context used to invoke the next valve
* in the current processing pipeline
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void invoke(Request request, Response response,
ValveContext context)
throws IOException, ServletException {
// Perform the request
context.invokeNext(request, response);
response.setSuspended(false);
ServletRequest sreq = request.getRequest();
Throwable t = (Throwable) sreq.getAttribute(Globals.EXCEPTION_ATTR);
if (t != null) {
throwable(request, response, t);
} else {
status(request, response);
}
}
示例5: getContextRelativePath
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Convert a possibly relative resource path into a context-relative
* resource path that starts with a '/'.
*
* @param request
* The servlet request we are processing
* @param relativePath
* The possibly relative resource path
*/
public static String getContextRelativePath(ServletRequest request, String relativePath) {
if (relativePath.startsWith("/"))
return (relativePath);
if (!(request instanceof HttpServletRequest))
return (relativePath);
HttpServletRequest hrequest = (HttpServletRequest) request;
String uri = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
if (uri != null) {
String pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
if (pathInfo == null) {
if (uri.lastIndexOf('/') >= 0)
uri = uri.substring(0, uri.lastIndexOf('/'));
}
} else {
uri = hrequest.getServletPath();
if (uri.lastIndexOf('/') >= 0)
uri = uri.substring(0, uri.lastIndexOf('/'));
}
return uri + '/' + relativePath;
}
示例6: 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);
}
}
}
}
示例7: cleanup
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
protected void cleanup(ServletRequest request, ServletResponse response, Exception existing) throws ServletException, IOException {
Exception exception = existing;
if (exception != null) {
Throwable unexpectedException = getUnexpectedException(existing);
Logger logger = LoggerFactory.getLogger(ExceptionFilter.class);
logger.error(exception.getCause().getMessage(), exception.getCause());
Boolean sessionCreationEnabled = (Boolean) request.getAttribute(WebSubjectContext.SESSION_CREATION_ENABLED);
if (sessionCreationEnabled != null && !sessionCreationEnabled) {
// We assume we are in a REST/JAX_RS call and thus return JSON
/*
FIXME Should we have different classes in diffrent Modules; I guess that is best
HttpServletResponse servletResponse = (HttpServletResponse) response;
servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
String code = unexpectedException == null ? "OCT-001" : "OCT-002";
ErrorInfo info = new ErrorInfo(code, exception.getMessage());
servletResponse.getWriter().print(info.toJSON());
*/
exception = null; // TODO
} else {
// Since we are in a finally block, this exception takes over and thus erasing all information we have about stacktraces
// OWASP A6
throw new AtbashUnexpectedException("Something went wrong");
}
}
super.cleanup(request, response, null);
}
示例8: doFilter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (!isGoodRequest(request)) {
FailReason reason = (FailReason) request.getAttribute(
Globals.PARAMETER_PARSE_FAILED_REASON_ATTR);
int status;
switch (reason) {
case IO_ERROR:
// Not the client's fault
status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
break;
case POST_TOO_LARGE:
status = HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE;
break;
case TOO_MANY_PARAMETERS:
// 413/414 aren't really correct here since the request body
// and/or URI could be well below any limits set. Use the
// default.
case UNKNOWN: // Assume the client is at fault
// Various things that the client can get wrong that don't have
// a specific status code so use the default.
case INVALID_CONTENT_TYPE:
case MULTIPART_CONFIG_INVALID:
case NO_NAME:
case REQUEST_BODY_INCOMPLETE:
case URL_DECODING:
case CLIENT_DISCONNECT:
// Client is never going to see this so this is really just
// for the access logs. The default is fine.
default:
// 400
status = HttpServletResponse.SC_BAD_REQUEST;
break;
}
((HttpServletResponse) response).sendError(status);
return;
}
chain.doFilter(request, response);
}
示例9: getContextRelativePath
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Convert a possibly relative resource path into a context-relative
* resource path that starts with a '/'.
*
* @param request The servlet request we are processing
* @param relativePath The possibly relative resource path
*/
public static String getContextRelativePath(ServletRequest request,
String relativePath) {
if (relativePath.startsWith("/"))
return (relativePath);
if (!(request instanceof HttpServletRequest))
return (relativePath);
HttpServletRequest hrequest = (HttpServletRequest) request;
String uri = (String)
request.getAttribute("javax.servlet.include.servlet_path");
if (uri != null) {
String pathInfo = (String)
request.getAttribute("javax.servlet.include.path_info");
if (pathInfo == null) {
if (uri.lastIndexOf('/') >= 0)
uri = uri.substring(0, uri.lastIndexOf('/'));
}
}
else {
uri = hrequest.getServletPath();
if (uri.lastIndexOf('/') >= 0)
uri = uri.substring(0, uri.lastIndexOf('/'));
}
return uri + '/' + relativePath;
}
示例10: getContextRelativePath
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Convert a possibly relative resource path into a context-relative
* resource path that starts with a '/'.
*
* @param request The servlet request we are processing
* @param relativePath The possibly relative resource path
*/
public static String getContextRelativePath(ServletRequest request,
String relativePath) {
if (relativePath.startsWith("/"))
return (relativePath);
if (!(request instanceof HttpServletRequest))
return (relativePath);
HttpServletRequest hrequest = (HttpServletRequest) request;
String uri = (String) request.getAttribute(
RequestDispatcher.INCLUDE_SERVLET_PATH);
if (uri != null) {
String pathInfo = (String)
request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
if (pathInfo == null) {
if (uri.lastIndexOf('/') >= 0)
uri = uri.substring(0, uri.lastIndexOf('/'));
}
}
else {
uri = hrequest.getServletPath();
if (uri.lastIndexOf('/') >= 0)
uri = uri.substring(0, uri.lastIndexOf('/'));
}
return uri + '/' + relativePath;
}
示例11: onAccessDenied
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response, Object mappedValue)
throws Exception {
HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
if(getLoginUrl().equals(httpServletRequest.getServletPath())&&"get".equalsIgnoreCase(httpServletRequest.getMethod())){
return true;
}
if (request.getAttribute(getFailureKeyAttribute()) != null) {
return true;
}
request.setAttribute("shiroLoginFailure", "用户未登录");
return super.onAccessDenied(request, response, mappedValue);
}
示例12: _initialize
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
private void _initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL,
boolean needsSession, int bufferSize, boolean autoFlush) {
// initialize state
this.servlet = servlet;
this.config = servlet.getServletConfig();
this.context = config.getServletContext();
this.errorPageURL = errorPageURL;
this.request = request;
this.response = response;
// initialize application context
this.applicationContext = JspApplicationContextImpl.getInstance(context);
// Setup session (if required)
if (request instanceof HttpServletRequest && needsSession)
this.session = ((HttpServletRequest) request).getSession();
if (needsSession && session == null)
throw new IllegalStateException("Page needs a session and none is available");
// initialize the initial out ...
depth = -1;
if (bufferSize == JspWriter.DEFAULT_BUFFER) {
bufferSize = Constants.DEFAULT_BUFFER_SIZE;
}
if (this.baseOut == null) {
this.baseOut = new JspWriterImpl(response, bufferSize, autoFlush);
} else {
this.baseOut.init(response, bufferSize, autoFlush);
}
this.out = baseOut;
// register names/values as per spec
setAttribute(OUT, this.out);
setAttribute(REQUEST, request);
setAttribute(RESPONSE, response);
if (session != null)
setAttribute(SESSION, session);
setAttribute(PAGE, servlet);
setAttribute(CONFIG, config);
setAttribute(PAGECONTEXT, this);
setAttribute(APPLICATION, context);
isIncluded = request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH) != null;
}
示例13: _initialize
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
private void _initialize(Servlet servlet, ServletRequest request,
ServletResponse response, String errorPageURL,
boolean needsSession, int bufferSize, boolean autoFlush) {
// initialize state
this.servlet = servlet;
this.config = servlet.getServletConfig();
this.context = config.getServletContext();
this.errorPageURL = errorPageURL;
this.request = request;
this.response = response;
// initialize application context
this.applicationContext = JspApplicationContextImpl.getInstance(context);
// Setup session (if required)
if (request instanceof HttpServletRequest && needsSession)
this.session = ((HttpServletRequest) request).getSession();
if (needsSession && session == null)
throw new IllegalStateException(
"Page needs a session and none is available");
// initialize the initial out ...
depth = -1;
if (bufferSize == JspWriter.DEFAULT_BUFFER) {
bufferSize = Constants.DEFAULT_BUFFER_SIZE;
}
if (this.baseOut == null) {
this.baseOut = new JspWriterImpl(response, bufferSize, autoFlush);
} else {
this.baseOut.init(response, bufferSize, autoFlush);
}
this.out = baseOut;
// register names/values as per spec
setAttribute(OUT, this.out);
setAttribute(REQUEST, request);
setAttribute(RESPONSE, response);
if (session != null)
setAttribute(SESSION, session);
setAttribute(PAGE, servlet);
setAttribute(CONFIG, config);
setAttribute(PAGECONTEXT, this);
setAttribute(APPLICATION, context);
isIncluded = request.getAttribute(
RequestDispatcher.INCLUDE_SERVLET_PATH) != null;
}
示例14: invoke
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Invoke the next Valve in the sequence. When the invoke returns, check
* the response state, and output an error report is necessary.
*
* @param request The servlet request to be processed
* @param response The servlet response to be created
* @param context The valve context used to invoke the next valve
* in the current processing pipeline
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void invoke(Request request, Response response,
ValveContext context)
throws IOException, ServletException {
// Perform the request
context.invokeNext(request, response);
ServletRequest sreq = (ServletRequest) request;
Throwable throwable =
(Throwable) sreq.getAttribute(Globals.EXCEPTION_ATTR);
ServletResponse sresp = (ServletResponse) response;
if (sresp.isCommitted()) {
return;
}
if (throwable != null) {
// The response is an error
response.setError();
// Reset the response (if possible)
try {
sresp.reset();
} catch (IllegalStateException e) {
;
}
ServletResponse sresponse = (ServletResponse) response;
if (sresponse instanceof HttpServletResponse)
((HttpServletResponse) sresponse).sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
response.setSuspended(false);
try {
report(request, response, throwable);
} catch (Throwable tt) {
tt.printStackTrace();
}
}
示例15: getStoredConnection
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public static Connection getStoredConnection(ServletRequest request) {
Connection conn = (Connection) request.getAttribute(ATT_NAME_CONNECTION);
return conn;
}