public static void setUserSession(HttpServletRequest request, String propertyName, Object obj) { UserSession gus = (UserSession) WebUtils.getSessionAttribute(request, Constant.SESS_USER); if (propertyName.equals(PROPERTY_USER)) gus.setUser((User) obj); else if (propertyName.equals(PROPERTY_LOGIN)) gus.setLogin((Integer) obj); else if (propertyName.equals(PROPERTY_BOX_LIST)) gus.setBoxList((List) obj); else if (propertyName.equals(PROPERTY_SEARCH)) gus.setSearchKey((String) obj); }
@Override protected String getText( final Arguments arguments, final Element element, final String attributeName) { final String attributeValue = element.getAttributeValue(attributeName); Money price = null; Object result = StandardExpressionProcessor.processExpression(arguments, attributeValue); if (result instanceof Money) { price = (Money) result; } else if (result instanceof BigDecimal) { price = new Money((BigDecimal) result); } else if (result == null) { price = Money.ZERO; } else { throw new IllegalArgumentException("Input is not of type Money or BigDecimal"); } HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); Locale curLocale = (Locale) WebUtils.getSessionAttribute( curRequest, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME); curLocale = (curLocale == null) ? Locale.US : curLocale; NumberFormat format = NumberFormat.getCurrencyInstance(curLocale); format.setCurrency(price.getCurrency()); return format.format(price.getAmount()); }
public static Object getUserSession(HttpServletRequest request, String propertyName) { UserSession gus = (UserSession) WebUtils.getSessionAttribute(request, Constant.SESS_USER); if (gus != null && propertyName.equals(PROPERTY_USER)) return gus.getUser(); else if (gus != null && propertyName.equals(PROPERTY_LOGIN)) return gus.getLogin(); else if (gus != null && propertyName.equals(PROPERTY_BOX_LIST)) return gus.getBoxList(); else if (gus != null && propertyName.equals(PROPERTY_SEARCH)) return gus.getSearchKey(); return null; }
protected Object formBackingObject(HttpServletRequest request) throws Exception { UserSession userSession = (UserSession) WebUtils.getSessionAttribute(request, "userSession"); if (userSession != null) { return new AccountForm(this.petStore.getAccount(userSession.getAccount().getUsername())); } else { return new AccountForm(); } }
public MySession getMySession() { MySession mySession = (MySession) WebUtils.getSessionAttribute(getRequest(), "MySession"); if (mySession != null) { return mySession; } else { showMessage2("页面长时间不活动,已推出", "/login.jsp"); return null; } }
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HttpSessionThreadLocal.set(request.getSession()); String username = (String) WebUtils.getSessionAttribute(request, LoginController.USER_NAME); Long userId = (Long) WebUtils.getSessionAttribute(request, LoginController.USER_ID); logger.debug("Intercepting username: "******"Intercepting for object: " + handler.getClass().getName()); if (username == null && userId == null) { if (checkForUserCookie(request, response)) { return true; } storeRequestInSession(request); logger.debug("username is null. Not logged in."); ModelAndView modelAndView = new ModelAndView(view); throw new ModelAndViewDefiningException(modelAndView); } else { logger.debug("Logged in, returning true"); return true; } }
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { UserSession userSession = (UserSession) WebUtils.getSessionAttribute(request, "userSession"); Cart cart = (Cart) WebUtils.getOrCreateSessionAttribute(request.getSession(), "sessionCart", Cart.class); String page = request.getParameter("page"); if (userSession != null) { if ("next".equals(page)) { userSession.getMyList().nextPage(); } else if ("previous".equals(page)) { userSession.getMyList().previousPage(); } } if ("nextCart".equals(page)) { cart.getCartItemList().nextPage(); } else if ("previousCart".equals(page)) { cart.getCartItemList().previousPage(); } return new ModelAndView(this.successView, "cart", cart); }
public static boolean empty(HttpServletRequest request) { return WebUtils.getSessionAttribute(request, Constant.SESS_USER) == null; }