Helper function to check for the session - Java Servlet JSP

Java examples for Servlet JSP:Servlet

Description

Helper function to check for the session

Demo Code


import java.io.File;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class Main{
    /**/*from w w w .j a v a2 s .  co m*/
     * Helper function to check for the session
     * @param req
     * @return
     */

    public static boolean isReqInSession(HttpServletRequest req) {
        boolean isReqInSession = false;
        HttpSession session = req.getSession(false);
        if (session == null) {
            return isReqInSession;
        }
        Integer accountantId = (Integer) session
                .getAttribute("accountantid");
        if (accountantId == null) {
            return isReqInSession;
        }
        isReqInSession = true;
        return isReqInSession;
    }
}

Related Tutorials