Example usage for javax.servlet.http HttpServletRequest getSession

List of usage examples for javax.servlet.http HttpServletRequest getSession

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getSession.

Prototype

public HttpSession getSession(boolean create);

Source Link

Document

Returns the current <code>HttpSession</code> associated with this request or, if there is no current session and <code>create</code> is true, returns a new session.

Usage

From source file:com.googlecode.psiprobe.controllers.sql.QueryHistoryController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    HttpSession sess = request.getSession(false);
    List queryHistory = null;/*from   www  .ja  v  a2 s .com*/

    if (sess != null) {
        DataSourceTestInfo sessData = (DataSourceTestInfo) sess
                .getAttribute(DataSourceTestInfo.DS_TEST_SESS_ATTR);

        if (sessData != null) {
            queryHistory = sessData.getQueryHistory();
        }
    }

    return new ModelAndView(getViewName(), "queryHistory", queryHistory);
}

From source file:CounterServer.java

public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession(true);
    int count = 1;
    Integer i = (Integer) session.getAttribute(COUNTER_KEY);
    if (i != null) {
        count = i.intValue() + 5;/*from   w ww .  ja  va  2  s.  c o m*/
    }
    session.setAttribute(COUNTER_KEY, new Integer(count));
    DataInputStream in = new DataInputStream(req.getInputStream());
    resp.setContentType("application/octet-stream");
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(byteOut);
    out.writeInt(count);
    out.flush();
    byte[] buf = byteOut.toByteArray();
    resp.setContentLength(buf.length);
    ServletOutputStream servletOut = resp.getOutputStream();
    servletOut.write(buf);
    servletOut.close();
}

From source file:com.mobilewallet.admin.action.AdminAction.java

/**
 * This is the action called from the Struts framework.
 *
 * @param mapping The ActionMapping used to select this instance.
 * @param form The optional ActionForm bean for this request.
 * @param request The HTTP Request we are processing.
 * @param response The HTTP Response we are processing.
 * @throws java.lang.Exception/*from   w w  w .jav a 2 s . c o  m*/
 * @return
 */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    HttpSession session = request.getSession(false);
    if (session == null || session.getAttribute("adminUser") == null) {
        return mapping.findForward(SHOW_ADMIN_HOME);
    }
    return mapping.findForward(DISPLAY_LOGINPAGE);
}

From source file:net.sourceforge.vulcan.web.PreferencesFilter.java

private void setupPreferences(HttpServletRequest request) {
    final HttpSession session = request.getSession(false);

    if (session != null && session.getAttribute(Keys.PREFERENCES) != null) {
        return;/*  w  w  w.  j ava 2s.com*/
    }

    final PreferencesDto prefs;

    final String cookieData = getCookieData(request, Keys.PREFERENCES);

    if (cookieData == null) {
        prefs = store.getDefaultPreferences();
    } else {
        prefs = store.convertFromString(cookieData);
    }

    if (session == null) {
        request.setAttribute(Keys.PREFERENCES, prefs);
    } else if (session.getAttribute(Keys.PREFERENCES) == null) {
        session.setAttribute(Keys.PREFERENCES, prefs);
    }
}