Java Code Examples for javax.servlet.jsp.PageContext#getSession()

The following examples show how to use javax.servlet.jsp.PageContext#getSession() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AgnUtils.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
public static ComAdmin getAdmin(PageContext pageContext) {
	try {
		HttpSession session = pageContext.getSession();
		if (session == null) {
			logger.error("No pageContext data found for getAdmin");
			return null;
		} else {
			ComAdmin admin = (ComAdmin) session.getAttribute(SESSION_CONTEXT_KEYNAME_ADMIN);
			if (admin == null) {
				logger.debug("No admin found in pageContext data");
				return null;
			} else {
				return admin;
			}
		}
	} catch (Exception e) {
		logger.error("No admin found for pageContext", e);
		return null;
	}
}
 
Example 2
Source File: MessageOpenTag.java    From JspMyAdmin2 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void doTag() throws JspException {
	PageContext pageContext = (PageContext) super.getJspContext();
	HttpSession httpSession = pageContext.getSession();
	MessageReader messageReader = null;
	if (httpSession != null) {
		Object temp = httpSession
				.getAttribute(Constants.SESSION_LOCALE);
		if (temp != null) {
			messageReader = new MessageReader(temp.toString());
		} else {
			messageReader = new MessageReader(null);
		}
	} else {
		messageReader = new MessageReader(null);
	}
	pageContext.setAttribute(Constants.PAGE_CONTEXT_MESSAGES,
			messageReader, PageContext.PAGE_SCOPE);
}
 
Example 3
Source File: FlashMessageTag.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public void doTag() throws IOException {
    final PageContext pageContext = (PageContext) getJspContext();
    final JspWriter jspWriter = pageContext.getOut();
    final HttpSession session = pageContext.getSession();

    for (final String flash : new String[]{SUCCESS_MESSAGE_KEY, WARNING_MESSAGE_KEY, ERROR_MESSAGE_KEY}) {
        final Object flashValue = session.getAttribute(flash);
        if (flashValue != null) {
            jspWriter.append(String.format("<div class='%s'>%s</div>", flash, flashValue));
            session.setAttribute(flash, null);
        }
    }

}
 
Example 4
Source File: WebBean.java    From Openfire with Apache License 2.0 5 votes vote down vote up
public void init(PageContext pageContext){
    this.request = (HttpServletRequest)pageContext.getRequest();
    this.response = (HttpServletResponse)pageContext.getResponse();
    this.session = pageContext.getSession();
    this.application = pageContext.getServletContext();
    this.out = pageContext.getOut();
}