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:psiprobe.controllers.jsp.RecompileJspController.java

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

    HttpSession session = request.getSession(false);
    Summary summary = (Summary) session.getAttribute(DisplayJspController.SUMMARY_ATTRIBUTE);

    if (request.getMethod().equalsIgnoreCase("post") && summary != null) {
        List<String> names = new ArrayList<>();
        for (String name : Collections.list(request.getParameterNames())) {
            if ("on".equals(request.getParameter(name))) {
                names.add(name);//  w w w . j  a  va 2s  .c  om
            }
        }
        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<String> 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()));
}

From source file:be.fedict.eid.dss.admin.portal.AccountingExportServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");

    HttpSession httpSession = request.getSession();
    Identity identity = (Identity) httpSession.getAttribute("org.jboss.seam.security.identity");
    if (false == identity.hasRole("admin")) {
        response.sendError(HttpURLConnection.HTTP_FORBIDDEN, "no admin role");
        return;/*w  ww . ja va 2  s .co  m*/
    }

    response.setContentType("text/csv");
    PrintWriter printWriter = response.getWriter();
    List<AccountingEntity> accountingEntities = this.accountingService.listAll();
    for (AccountingEntity accountingEntity : accountingEntities) {
        printWriter.print("\"");
        printWriter.print(accountingEntity.getDomain());
        printWriter.print("\",\"");
        printWriter.print(accountingEntity.getRequests());
        printWriter.println("\"");
    }
}

From source file:com.att.api.immn.controller.DelMsgController.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);
    final String msgIdStr = request.getParameter("deleteMsgId");
    final String[] msgIds = msgIdStr.split(",");

    JSONObject jresponse = new JSONObject();
    try {//from  w  ww  . ja v  a  2  s.c  o m
        if (msgIds.length > 1) {
            srvc.deleteMessages(msgIds);
        } else {
            final String msgId = msgIds[0];
            srvc.deleteMessage(msgId);
        }
        jresponse.put("success", true).put("text", "Message(s) deleted.");
    } 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:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration.java

public static String newEditKey(HttpSession sess) {
    DateTime time = new DateTime();
    int mills = time.getMillisOfDay();

    Map<String, EditConfiguration> configs = (Map<String, EditConfiguration>) sess
            .getAttribute("EditConfigurations");
    if (configs == null) {
        return Integer.toString(mills);
    } else {/*from   w  ww  . j av a  2  s. c o m*/
        while (configs.containsKey(Integer.toString(mills))) {
            mills++;
        }
        return Integer.toString(mills);
    }
}

From source file:mx.com.quadrum.contratos.controller.service.user.EmpleadoQuadrumController.java

@ResponseBody
@RequestMapping(value = "aprobarContrato", method = RequestMethod.POST)
public String aprobarContrato(@RequestBody String id, HttpSession session) {
    if (session.getAttribute("usuario") == null) {
        return SESION_CADUCA;
    }//from  www . j  a  v  a2 s  .c om
    return contratoService.aprobarContrato(Integer.parseInt(id.replace("=", "")));
}

From source file:mx.com.quadrum.contratos.controller.service.user.EmpleadoQuadrumController.java

@ResponseBody
@RequestMapping(value = "rechazarContrato", method = RequestMethod.POST)
public String rechazarContrato(@RequestBody String id, HttpSession session) {
    if (session.getAttribute("usuario") == null) {
        return SESION_CADUCA;
    }//w w w . j a  v  a 2 s .co  m
    return contratoService.rechazarContrato(Integer.parseInt(id.replace("=", "")));
}

From source file:org.owasp.webgoat.service.BaseService.java

/**
 * <p>getWebSession.</p>/*from  w w w.  j  ava2 s .  co m*/
 *
 * @param session a {@link javax.servlet.http.HttpSession} object.
 * @return a {@link org.owasp.webgoat.session.WebSession} object.
 */
public WebSession getWebSession(HttpSession session) {
    WebSession ws;
    Object o = session.getAttribute(WebSession.SESSION);
    if (o == null) {
        throw new IllegalArgumentException(
                "No valid WebSession object found, has session timed out? [" + session.getId() + "]");
    }
    if (!(o instanceof WebSession)) {
        throw new IllegalArgumentException("Invalid WebSession object found, this is probably a bug! ["
                + o.getClass() + " | " + session.getId() + "]");
    }
    ws = (WebSession) o;
    return ws;
}

From source file:dicky.controlleruser.CartController.java

@RequestMapping(value = "delete/{index}", method = RequestMethod.GET)
public String delete(@PathVariable("index") int index, HttpSession session) {
    List<Item> cart = (List<Item>) session.getAttribute("cart");
    cart.remove(index);//from ww w.  j  ava 2 s.  c  om
    session.setAttribute("cart", cart);
    return "redirect:/cart.html";
}

From source file:miage.ecom.web.controller.CartController.java

@RequestMapping(value = "/cart/checkout", method = RequestMethod.POST)
public String checkout(HttpSession session, Model model) {
    Customer customer = (Customer) session.getAttribute("customer");
    if (customer == null) {
        model.addAttribute("loginError", "You have to be logged in in order to checkout");
        return "login";
    }//from   w  ww .  j a  v  a 2s. co  m

    return "home";
}

From source file:be.fedict.eid.dss.portal.DownloadServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");
    HttpSession httpSession = request.getSession();
    byte[] document = (byte[]) httpSession.getAttribute(this.documentSessionAttribute);

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1
    if (false == request.getScheme().equals("https")) {
        // else the download fails in IE
        response.setHeader("Pragma", "no-cache"); // http 1.0
    } else {//from   ww  w . j  a  v a  2  s . c o  m
        response.setHeader("Pragma", "public");
    }
    response.setDateHeader("Expires", -1);
    response.setContentLength(document.length);

    String contentType = (String) httpSession.getAttribute(this.contentTypeSessionAttribute);
    LOG.debug("content-type: " + contentType);
    response.setContentType(contentType);
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}