State

// Save and get a request-scoped value
req.setAttribute("com.mycompany.req-param", "req-value");
Object value = req.getAttribute("com.mycompany.req-param");

// Save and get a session-scoped value
HttpSession session = req.getSession(false);
if (session != null) {
    session.setAttribute("com.mycompany.session-param", "session-value");
    value = session.getAttribute("com.mycompany.session-param");
}

// Save and get an application-scoped value
getServletContext().setAttribute("com.mycompany.app-param", "app-value");
value = getServletContext().getAttribute("com.mycompany.app-param");

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.