List of usage examples for javax.servlet.http HttpServletRequest getAttribute
public Object getAttribute(String name);
Object
, or null
if no attribute of the given name exists. From source file:com.huateng.ebank.framework.web.struts.ActionExceptionHandler.java
/** * This method overrides the the ExceptionHandler's storeException method in * order to create more than one error message. * /*www. j ava 2 s.c om*/ * @param request - * The request we are handling * @param property - * The property name to use for this error * @param error - * The error generated from the exception mapping * @param forward - * The forward generated from the input path (from the form or * exception mapping) */ protected void storeException(HttpServletRequest request, String property, ActionMessage error, ActionForward forward) { ActionMessages errors = (ActionMessages) request.getAttribute(Globals.ERROR_KEY); if (errors == null) { errors = new ActionMessages(); } errors.add(property, error); request.setAttribute(Globals.ERROR_KEY, errors); }
From source file:org.iwethey.forums.web.user.UserController.java
/** * Toggle binary settings. Requires a request parameter of "toggle" * that contains the name of the property to toggle. *///from ww w. ja v a2 s.c o m public ModelAndView toggle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { User user = (User) request.getAttribute(USER_ATTRIBUTE); String propName = RequestUtils.getStringParameter(request, "toggle", null); if (user != null && propName != null && !propName.equals("")) { BeanWrapper wrap = new BeanWrapperImpl(user); Boolean val = (Boolean) wrap.getPropertyValue(propName); wrap.setPropertyValue(propName, new Boolean(!val.booleanValue())); userManager.saveUserAttributes(user); } return new ModelAndView(new RedirectView(request.getHeader("referer"))); }
From source file:com.wiiyaya.consumer.web.main.controller.ExceptionController.java
@RequestMapping(MainURIResource.PATH_ERROR_ALL) public String error(HttpServletRequest request) throws Throwable { Integer code = (Integer) request.getAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE); Throwable exception = (Throwable) request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE); String simpleMsg = (String) request.getAttribute(WebUtils.ERROR_MESSAGE_ATTRIBUTE); if (exception != null) { throw getRootCause(exception); } else {//w w w .j a v a2s.c o m switch (code) { case 404: throw new PageNotFoundException(); case 403: throw new AccessDeniedException(simpleMsg); default: throw new Exception(simpleMsg); } } }
From source file:org.tangram.spring.MeasureTimeInterceptor.java
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { String thisURL = request.getRequestURI(); if (!getFreeUrls().contains(thisURL)) { Long startTime = (Long) request.getAttribute("start.time"); statistics.avg("page render time", System.currentTimeMillis() - startTime); } // if/* w w w . j av a 2 s . c o m*/ super.afterCompletion(request, response, handler, ex); }
From source file:com.greenline.guahao.web.module.common.interceptor.CookieInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if (isAddSessionCookie) { CookieModule jar = (CookieModule) request.getAttribute(CookieModule.COOKIE); if (jar == null) { return; }// ww w . j a va 2 s .c o m String sessionId = jar.get(shortCookieName); // mark?marksessionId if (StringUtils.isBlank(UserCookieUtil.getMark(request))) { // ? Date now = new Date(); jar.set(shortCookieName, now.getTime() + 5); jar.set(expiryMark, now.getTime() + 10); } else { // mark??sessionId if (StringUtils.isBlank(sessionId)) { // ? Date now = new Date(); jar.set(shortCookieName, now.getTime() + 5); } } } }
From source file:de.hybris.platform.addonsupport.controllers.cms.AbstractCMSAddOnComponentController.java
@RequestMapping public String handleGet(final HttpServletRequest request, final HttpServletResponse response, final Model model) throws Exception { T component = (T) request.getAttribute(COMPONENT); if (component != null) { // Add the component to the model model.addAttribute("component", component); // Allow subclasses to handle the component return handleComponent(request, response, model, component); }/* w w w .jav a 2s.c om*/ String componentUid = (String) request.getAttribute(COMPONENT_UID); if (StringUtils.isEmpty(componentUid)) { componentUid = request.getParameter(COMPONENT_UID); } if (StringUtils.isEmpty(componentUid)) { LOG.error("No component specified in [" + COMPONENT_UID + "]"); throw new HttpNotFoundException(); } try { component = (T) getCmsComponentService().getAbstractCMSComponent(componentUid); if (component == null) { LOG.error("Component with UID [" + componentUid + "] is null"); throw new HttpNotFoundException(); } else { // Add the component to the model model.addAttribute("component", component); // Allow subclasses to handle the component return handleComponent(request, response, model, component); } } catch (final CMSItemNotFoundException e) { LOG.error("Could not find component with UID [" + componentUid + "]"); throw new HttpNotFoundException(e); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.ManageExecutionCourseDA.java
public ActionForward prepare(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { InfoExecutionCourse infoExecutionCourse = (InfoExecutionCourse) request .getAttribute(PresentationConstants.EXECUTION_COURSE); ExecutionCourse executionCourse = infoExecutionCourse.getExecutionCourse(); readAndSetExecutionCourseClasses(request, executionCourse); request.setAttribute("courseLoadBean", new CourseLoadBean(executionCourse)); return mapping.findForward("ManageExecutionCourse"); }
From source file:com.wiiyaya.consumer.web.main.controller.ExceptionController.java
/** * // w ww .j a va 2 s . com * @param request ? * @param exception * @return ExceptionDto JSON */ @ExceptionHandler @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public ModelAndView springErrorHand(HttpServletRequest request, Exception exception) { String simpleMsg = (String) request.getAttribute(WebUtils.ERROR_MESSAGE_ATTRIBUTE); String errorCode = exception == null ? simpleMsg : exception.getClass().getSimpleName(); String errorMessage = exception == null ? simpleMsg : exception.getMessage(); LOGGER.error("Error catch: statusCode[{}], errorMessage[{}], errorUrl[{}]", HttpStatus.INTERNAL_SERVER_ERROR.value(), errorMessage, request.getRequestURI(), exception); return prepareExceptionInfo(request, HttpStatus.INTERNAL_SERVER_ERROR, errorCode, errorMessage); }
From source file:org.smigo.log.LogHandler.java
public void logError(HttpServletRequest request, HttpServletResponse response, Exception ex, String subject) { final String uri = (String) request.getAttribute("javax.servlet.error.request_uri"); final Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); final String separator = System.lineSeparator(); StringBuilder text = new StringBuilder(); text.append(getRequestDump(request, response, separator)).append(separator); text.append("Statuscode:").append(statusCode).append(separator); text.append("Uri:").append(uri).append(separator); text.append("Exception:").append(getStackTrace(ex)).append(separator); log.error("Error during request" + subject, ex); if (!Log.create(request, response).getUseragent().contains("compatible")) { mailHandler.sendAdminNotification("error during request " + subject, text); }/*from www . j av a 2 s . c om*/ }
From source file:net.sourceforge.fenixedu.presentationTier.Action.coordinator.SearchDegreeLogAction.java
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {//w ww . ja va 2 s.c o m request.setAttribute("degreeCurricularPlanID", request.getAttribute("degreeCurricularPlanID")); SearchDegreeLogBean bean = getRenderedObject(); RenderUtils.invalidateViewState(); searchLogs(bean); request.setAttribute("searchBean", bean); request.setAttribute("degree", bean.getDegree()); prepareAttendsCollectionPages(request, bean, bean.getDegree()); return mapping.findForward("search"); }