Example usage for javax.servlet.http HttpSession getAttribute

List of usage examples for javax.servlet.http HttpSession getAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession getAttribute.

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the object bound with the specified name in this session, or null if no object is bound under the name.

Usage

From source file:com.att.api.immn.controller.GetMsgIndexInfoController.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final HttpSession session = request.getSession();
    OAuthToken token = (OAuthToken) session.getAttribute("token");
    IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token);

    JSONObject jresponse = new JSONObject();
    try {/*from  w  ww .  j a  va 2s .  c o m*/
        final MessageIndexInfo info = srvc.getMessageIndexInfo();

        final JSONArray tables = new JSONArray();
        final JSONArray values = new JSONArray().put(info.getStatus()).put(info.getState())
                .put(info.getMessageCount());
        tables.put(new JSONObject().put("caption", "Message Index Info:")
                .put("headers", new JSONArray().put("Status").put("State").put("Message Count"))
                .put("values", new JSONArray().put(values)));
        jresponse.put("success", true).put("tables", tables);
    } catch (RESTException re) {
        jresponse.put("success", false).put("text", re.getMessage());
    }

    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.print(jresponse);
    writer.flush();
}

From source file:cs425.yogastudio.controller.CustomerController.java

@RequestMapping(value = "/signUpSuccess", method = RequestMethod.GET)
public String goToSignUpSuccess(Model model, HttpSession session) {

    model.addAttribute("added", session.getAttribute("added"));

    return "signUpSuccess";
}

From source file:de.laures.cewolf.storage.AbstractSessionStorage.java

/**
 * @see de.laures.cewolf.Storage#getChartImage(String)
 *//*from   w  w  w. ja v  a2  s.  c o  m*/
public ChartImage getChartImage(String id, HttpServletRequest request) {
    HttpSession session = request.getSession();
    return (ChartImage) session.getAttribute(id);
}

From source file:com.bvvy.photo.web.controller.PgerContoller.java

@RequestMapping(value = "/pger", method = RequestMethod.GET)
@AuthMethod(role = "ROLE_COMMON")
public String add(Model model, HttpSession session) {
    User loginUser = (User) session.getAttribute("loginUser");
    if (CommonUitl.isEmpty(loginUser))
        return "redirect:/login";
    model.addAttribute(new Pger());
    return "front/pger/add";

}

From source file:dicky.controlleruser.CartController.java

private int isExsist(String id, HttpSession session) {
    List<Item> cart = (List<Item>) session.getAttribute("cart");
    for (int i = 0; i < cart.size(); i++) {
        if (cart.get(i).getProduct().getIdProduct().equals(id)) {
            return i;
        }/*from www  . j a  va2 s.c o m*/
    }
    return -1;
}

From source file:per.mnn.controller.CartController.java

private ShoppingCart checkCart(HttpServletRequest request) {

    HttpSession httpSess = request.getSession();
    ShoppingCart cart = (ShoppingCart) httpSess.getAttribute("cart");
    if (cart == null) {
        cart = new ShoppingCart();
        httpSess.setAttribute("cart", cart);
    }/*from w w w .  j av  a  2  s . c o  m*/

    return cart;
}

From source file:com.controller.email.GetEmailTagsServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from ww w.  jav a  2 s  .c  o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    List<Map<String, Object>> tagsFromMandrill = MandrillApiHandler.getTags();
    List<Map<String, Object>> tagsFromMandrillForUser = new ArrayList<>();

    HttpSession session = request.getSession();
    if (session.getAttribute("UID") == null || StringUtils.isEmpty(session.getAttribute("UID").toString())) {
        Map<String, String> responseMap = new HashMap<>();
        responseMap.put("error", "user is not logged in");
        response.getWriter().write(new Gson().toJson(responseMap));
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
    }
    int userId = Integer.parseInt(session.getAttribute("UID").toString());
    Set<String> tagsForUser = EmailHistoryDAO.getTagsForUser(userId);
    for (Map<String, Object> mTag : tagsFromMandrill) {
        if (mTag.get("tag") != null) {
            if (tagsForUser.contains(mTag.get("tag").toString())) {
                tagsFromMandrillForUser.add(mTag);
            }
        }
    }
    response.getWriter().write(new Gson().toJson(tagsFromMandrillForUser));

    response.getWriter().flush();
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:de.blizzy.documentr.web.access.AccessController.java

@RequestMapping(value = "/login/error", method = RequestMethod.GET)
@PreAuthorize("permitAll")
public String loginError(HttpSession session, Model model) {
    AuthenticationException exception = (AuthenticationException) session
            .getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
    String msg = getMessage(exception);
    if (StringUtils.isNotBlank(msg)) {
        model.addAttribute("errorMessage", msg); //$NON-NLS-1$
    }/*from   w ww. j  a  v  a2  s  .  c o m*/
    return "/login"; //$NON-NLS-1$
}

From source file:cn.vlabs.umt.ui.servlet.login.AppLogin.java

protected void onWrongPassword(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession();
    String loginURL = (String) session.getAttribute("applogin.LoginURL");
    String vmtApp = (String) session.getAttribute("applogin.LoginAPP");

    forwardToLogin(request, response, loginURL, vmtApp, true);
}

From source file:com.googlecode.psiprobe.controllers.jsp.RecompileJspController.java

protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    HttpSession session = request.getSession();
    Summary summary = session != null ? (Summary) session.getAttribute(DisplayJspController.SUMMARY_ATTRIBUTE)
            : null;/*  w  w  w .  j a  v a2s .  co m*/

    if (request.getMethod().equalsIgnoreCase("post") && summary != null) {
        List names = new ArrayList();
        for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
            String name = (String) e.nextElement();
            if ("on".equals(request.getParameter(name))) {
                names.add(name);
            }
        }
        getContainerWrapper().getTomcatContainer().recompileJsps(context, summary, names);
        session.setAttribute(DisplayJspController.SUMMARY_ATTRIBUTE, summary);
    } else if (summary != null && contextName.equals(summary.getName())) {
        String name = ServletRequestUtils.getStringParameter(request, "source", null);
        if (name != null) {
            List names = new ArrayList();
            names.add(name);
            getContainerWrapper().getTomcatContainer().recompileJsps(context, summary, names);
            session.setAttribute(DisplayJspController.SUMMARY_ATTRIBUTE, summary);
        } else {
            logger.error("source is not passed, nothing to do");
        }
    }
    return new ModelAndView(new RedirectView(
            request.getContextPath() + ServletRequestUtils.getStringParameter(request, "view", getViewName())
                    + "?" + request.getQueryString()));
}