本文整理匯總了Java中javax.servlet.http.HttpServletRequest.removeAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.removeAttribute方法的具體用法?Java HttpServletRequest.removeAttribute怎麽用?Java HttpServletRequest.removeAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.removeAttribute方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runCallbacks
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void runCallbacks(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
{
List<WebFilterCallback> callbacks = (List<WebFilterCallback>) httpRequest.getAttribute(CALLBACKS_KEY);
httpRequest.removeAttribute(CALLBACKS_KEY);
if( callbacks != null )
{
// Run them in reverse, don't let one callback stop the rest from happening
for( int i = callbacks.size() - 1; i >= 0; i-- )
{
try
{
callbacks.get(i).afterServlet(httpRequest, httpResponse);
}
catch( Exception e )
{
LOGGER.error("Error running callback", e);
}
}
}
}
示例2: exposeModelAsRequestAttributes
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Expose the model objects in the given map as request attributes.
* Names will be taken from the model Map.
* This method is suitable for all resources reachable by {@link javax.servlet.RequestDispatcher}.
* @param model Map of model objects to expose
* @param request current HTTP request
*/
protected void exposeModelAsRequestAttributes(Map<String, Object> model, HttpServletRequest request) throws Exception {
for (Map.Entry<String, Object> entry : model.entrySet()) {
String modelName = entry.getKey();
Object modelValue = entry.getValue();
if (modelValue != null) {
request.setAttribute(modelName, modelValue);
if (logger.isDebugEnabled()) {
logger.debug("Added model object '" + modelName + "' of type [" + modelValue.getClass().getName() +
"] to request in view");
}
}
else {
request.removeAttribute(modelName);
if (logger.isDebugEnabled()) {
logger.debug("Removed model object '" + modelName +
"' from request in view");
}
}
}
}
示例3: processRequest
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Event Listeners</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet Event Listeners</h1>");
out.println("<h2>Setting, updating, and removing ServletContext Attributes</h2>");
request.getServletContext().setAttribute("attribute1", "attribute-value1");
request.getServletContext().setAttribute("attribute1", "attribute-updated-value1");
request.getServletContext().removeAttribute("attribute1");
out.println("done");
out.println("<h2>Setting, updating, and removing HttpSession Attributes</h2>");
request.getSession(true).setAttribute("attribute1", "attribute-value1");
request.getSession().setAttribute("attribute1", "attribute-updated-value1");
request.getSession().removeAttribute("attribute1");
out.println("done");
out.println("<h2>Setting, updating, and removing ServletRequest Attributes</h2>");
request.setAttribute("attribute1", "attribute-value1");
request.setAttribute("attribute1", "attribute-updated-value1");
request.removeAttribute("attribute1");
out.println("done");
out.println("<h2>Invalidating session</h2>");
request.getSession().invalidate();
out.println("done");
out.println("<br><br>Check output in server log");
out.println("</body>");
out.println("</html>");
}
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:34,代碼來源:EventListenerServlet.java
示例4: postHandle
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
//super.postHandle(request, response, handler, modelAndView);
long startTime = (long) request.getAttribute("startTime");
request.removeAttribute("startTime");
long endTime = System.currentTimeMillis();
System.out.println("本次請求的時間為:"+new Long(endTime - startTime)+"ms");
request.setAttribute("handlingTime",endTime - startTime);
}
示例5: postHandle
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public void postHandle(HttpServletRequest request, //③
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
long startTime = (Long) request.getAttribute("startTime");
request.removeAttribute("startTime");
long endTime = System.currentTimeMillis();
System.out.println("本次請求處理時間為:" + new Long(endTime - startTime)+"ms");
request.setAttribute("handlingTime", endTime - startTime);
}
示例6: selectModule
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Select the module to which the specified request belongs, and
* add corresponding request attributes to this request.
*
* @param prefix The module prefix of the desired module
* @param request The servlet request we are processing
* @param context The ServletContext for this web application
*/
public void selectModule(
String prefix,
HttpServletRequest request,
ServletContext context) {
// Expose the resources for this module
ModuleConfig config = getModuleConfig(prefix, context);
if (config != null) {
request.setAttribute(Globals.MODULE_KEY, config);
} else {
request.removeAttribute(Globals.MODULE_KEY);
}
MessageResourcesConfig[] mrConfig = config.findMessageResourcesConfigs();
for(int i = 0; i < mrConfig.length; i++) {
String key = mrConfig[i].getKey();
MessageResources resources =
(MessageResources) context.getAttribute(key + prefix);
if (resources != null) {
request.setAttribute(key, resources);
} else {
request.removeAttribute(key);
}
}
}
示例7: addMessages
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Adds the specified messages keys into the appropriate request
* attribute for use by the <html:messages> tag (if
* messages="true" is set), if any messages are required.
* Initialize the attribute if it has not already been.
* Otherwise, ensure that the request attribute is not set.
*
* @param request The servlet request we are processing
* @param messages Messages object
* @since Struts 1.2.1
*/
protected void addMessages(
HttpServletRequest request,
ActionMessages messages) {
if (messages == null){
// bad programmer! *slap*
return;
}
// get any existing messages from the request, or make a new one
ActionMessages requestMessages = (ActionMessages) request.getAttribute(Globals.MESSAGE_KEY);
if (requestMessages == null){
requestMessages = new ActionMessages();
}
// add incoming messages
requestMessages.add(messages);
// if still empty, just wipe it out from the request
if (requestMessages.isEmpty()) {
request.removeAttribute(Globals.MESSAGE_KEY);
return;
}
// Save the messages
request.setAttribute(Globals.MESSAGE_KEY, requestMessages);
}
示例8: addErrors
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Adds the specified errors keys into the appropriate request attribute
* for use by the <html:errors> tag, if any messages are required.
* Initialize the attribute if it has not already been. Otherwise, ensure
* that the request attribute is not set.
*
* @param request The servlet request we are processing
* @param errors Errors object
* @since Struts 1.2.1
*/
protected void addErrors(
HttpServletRequest request,
ActionMessages errors) {
if (errors == null){
// bad programmer! *slap*
return;
}
// get any existing errors from the request, or make a new one
ActionMessages requestErrors = (ActionMessages)request.getAttribute(Globals.ERROR_KEY);
if (requestErrors == null){
requestErrors = new ActionMessages();
}
// add incoming errors
requestErrors.add(errors);
// if still empty, just wipe it out from the request
if (requestErrors.isEmpty()) {
request.removeAttribute(Globals.ERROR_KEY);
return;
}
// Save the errors
request.setAttribute(Globals.ERROR_KEY, requestErrors);
}
示例9: saveErrors
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* <p>Save the specified error messages keys into the appropriate request
* attribute for use by the <html:errors> tag, if any messages
* are required. Otherwise, ensure that the request attribute is not
* created.</p>
*
* @param request The servlet request we are processing
* @param errors Error messages object
* @since Struts 1.2
*/
protected void saveErrors(HttpServletRequest request, ActionMessages errors) {
// Remove any error messages attribute if none are required
if ((errors == null) || errors.isEmpty()) {
request.removeAttribute(Globals.ERROR_KEY);
return;
}
// Save the error messages we need
request.setAttribute(Globals.ERROR_KEY, errors);
}
示例10: saveMessages
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* <p>Save the specified messages keys into the appropriate request
* attribute for use by the <html:messages> tag (if
* messages="true" is set), if any messages are required. Otherwise,
* ensure that the request attribute is not created.</p>
*
* @param request The servlet request we are processing.
* @param messages The messages to save. <code>null</code> or empty
* messages removes any existing ActionMessages in the request.
*
* @since Struts 1.1
*/
protected void saveMessages(
HttpServletRequest request,
ActionMessages messages) {
// Remove any messages attribute if none are required
if ((messages == null) || messages.isEmpty()) {
request.removeAttribute(Globals.MESSAGE_KEY);
return;
}
// Save the messages we need
request.setAttribute(Globals.MESSAGE_KEY, messages);
}
示例11: getErrorData
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public ErrorData getErrorData(T ex, HttpServletRequest request) {
if (request.getAttribute(CONTROLLER_ERROR_HANDLING_ATTRIBUTE) != null) {
request.removeAttribute(CONTROLLER_ERROR_HANDLING_ATTRIBUTE);
throw (RuntimeException) ex;
}
return buildErrorData(ex, getHeadersAsText(request))
.withRequestMethod(request.getMethod())
.withRequestUri(request.getRequestURI())
.build();
}
示例12: around
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**配置環繞通知,使用在方法aspect()上注冊的切入點*/
@Around("aspect()")
public Object around(ProceedingJoinPoint pjd) {
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
Object result = null;
//執行目標方法
try {
//前置通知
result = pjd.proceed();
if(Statics.Record_System_Log){
if(result instanceof ReturnUtil){
List<JSONObject> operationLogs = ReflectHelperUtil.getInstance(result, "operation_logs");
if(operationLogs==null)operationLogs = new ArrayList<JSONObject>();
if(Statics.Record_Select_System_Log || (!Statics.Record_Select_System_Log && operationLogs.size()>0)){
if(request.getAttribute(Statics.SYSTEM_LOG_ID)!=null && !request.getAttribute(Statics.SYSTEM_LOG_ID).toString().equals("")){
//-----添加係統日誌begin-----
JSONObject log = JSONObject.parseObject(request.getAttribute(Statics.SYSTEM_LOG_ID).toString());
log.put("result", JSONObject.toJSONString(result));
long systemLogId = Long.parseLong(AuthorityAnnotationInterceptor.myBaseService.add(null,log, "systemMapper.addSystemLog", true).getExtend_info().toString());
//-----添加係統日誌end-----
JSONObject memberJson = StorageUtil.init(request.getSession()).getLoginMemberInfoJson();
if(memberJson!=null && operationLogs.size()>0){
for (int i = 0,length=operationLogs.size(); i < length; i++) {
JSONObject operationLog = operationLogs.get(i);
if(operationLog.getInteger("operation_type")!=3){
//-----添加操作日誌begin-----
operationLog.put("system_log_id", systemLogId);
operationLog.put("memberId", memberJson.getLong("id"));
AuthorityAnnotationInterceptor.myBaseService.add(null,operationLog, "systemMapper.addOperationLog",true);
//-----添加操作日誌end-----
}
}
}
}
}
}
}
request.removeAttribute("Statics.SYSTEM_LOG_ID");
//返回通知
} catch (Throwable e) {
//異常通知
if(result instanceof ReturnUtil){
result = ((ReturnUtil) result).addSeriousErrorMsg("發生異常:"+e.toString());
}else{
throw new RuntimeException(e);
}
e.printStackTrace();
}
//後置通知
if(Statics.out_implement_time){
long implement_time =System.currentTimeMillis() - Long.parseLong(request.getAttribute("start_implement_time").toString());
System.out.println(request.getAttribute("implement_method_name")+"方法處理時間:"+implement_time+"毫秒。");
}
return result;
}
示例13: doFilter
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* If the request contains a SAML 2.0 response, forward to the originally
* requested resource is done. In case of service login, the request is
* forwarded to an auto-submit page, to do the login in UserBean. <br/>
* If the response does not contain a SAML 2.0 response, the next filter is
* called. See web.xml for excluded url pattern.
*
*/
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
if (!httpRequest.getServletPath().matches(excludeUrlPattern)) {
if (containsSamlResponse(httpRequest)) {
httpRequest.setAttribute(Constants.REQ_ATTR_IS_SAML_FORWARD,
Boolean.TRUE);
String samlResponse = httpRequest.getParameter("SAMLResponse");
if (samlResponseExtractor.isFromLogout(samlResponse)) {
try {
if (!samlLogoutResponseValidator.responseStatusCodeSuccessful(samlResponse)) {
httpRequest.setAttribute(
Constants.REQ_ATTR_ERROR_KEY,
BaseBean.ERROR_INVALID_SAML_RESPONSE_STATUS_CODE);
redirector.forward(httpRequest, httpResponse,
BaseBean.ERROR_PAGE);
return;
}
HttpSession currentSession = httpRequest.getSession();
getSsl().deletePlatformSession(currentSession.getId());
currentSession.invalidate();
httpRequest.removeAttribute("SAMLResponse");
httpRequest.setAttribute(Constants.REQ_ATTR_IS_SAML_FORWARD,
Boolean.FALSE);
} catch (SAML2StatusCodeInvalidException e) {
httpRequest.setAttribute(
Constants.REQ_ATTR_ERROR_KEY,
BaseBean.ERROR_INVALID_SAML_RESPONSE);
redirector.forward(httpRequest, httpResponse,
BaseBean.ERROR_PAGE);
LOGGER.logError(Log4jLogger.SYSTEM_LOG, e,
ERROR_SAML2_INVALID_STATUS_CODE);
return;
}
String relayState = httpRequest.getParameter("RelayState");
if (relayState != null) {
String forwardUrl = getForwardUrl(httpRequest, relayState);
((HttpServletResponse) response).sendRedirect(forwardUrl);
return;
}
if (httpRequest
.getAttribute(Constants.REQ_ATTR_ERROR_KEY) != null) {
redirector.forward(httpRequest, httpResponse,
BaseBean.ERROR_PAGE);
return;
}
httpRequest.setAttribute(Constants.REQ_ATTR_IS_SAML_FORWARD,
Boolean.FALSE);
}
}
}
chain.doFilter(request, response);
}
示例14: deleteReference
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Deletes the nested reference from the request object.
* @param request object to remove the reference from
*/
public static final void deleteReference(HttpServletRequest request) {
// delete the reference
request.removeAttribute(NESTED_INCLUDES_KEY);
}