Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SessionUtils {
- public static HttpSession getSession() {
- return (HttpSession) FacesContext.getCurrentInstance()
- .getExternalContext().getSession(false);
- }
- public static HttpServletRequest getRequest() {
- return (HttpServletRequest) FacesContext.getCurrentInstance()
- .getExternalContext().getRequest();
- }
- public static String getUserEmail() {
- HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
- .getExternalContext().getSession(false);
- return session.getAttribute("email").toString();
- }
- public static String getUserId() {
- HttpSession session = getSession();
- if (session != null)
- return (String) session.getAttribute("userid");
- else
- return null;
- }
- }
- a part of index.xhtml
- <c:if test='#{authenticateBean.GetSession() ne null}'>
- <c:if test='#{authenticateBean.GetUserEmail() ne "admin@gmail.com"}'>
- <ul class="links">
- <li >
- <h:link value="add" outcome="GoodBasket" />
- </li>
- </ul>
- </c:if>
- </c:if>
- @Override
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
- HttpServletRequest reqt = (HttpServletRequest) request;
- HttpServletResponse resp = (HttpServletResponse) response;
- HttpSession ses = reqt.getSession(false);
- String reqURI = reqt.getRequestURI();
- if ((reqURI.indexOf("/index.xhtml") >= 0))
- chain.doFilter(request, response);
- else
- resp.sendRedirect(reqt.getContextPath() + "/JSFViews/Login.xhtml");
- }
- public String Login(){
- UsersModel user= userServices.Login(email,password);
- if (user!=null) {
- HttpSession session = SessionUtils.getSession();
- session.setAttribute("email", email);
- return "ProductRegisteration";
- } else {
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
- "Incorrect Username and Passowrd", "Please enter correct username and Password"));
- return "Login";
- }
- }
- public String GetUserEmail()
- {
- return SessionUtils.getUserEmail();
- }
- public HttpSession GetSession()
- {
- return SessionUtils.getSession();
- }
- javax.servlet.ServletException: /JSFViews/index.xhtml @109,86 test="#{authenticateBean.GetUserEmail() ne "admin@gmail.com"}" /JSFViews/index.xhtml @109,86 test="#{authenticateBean.GetUserEmail() ne "admin@gmail.com"}": java.lang.NullPointerException
- javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
- org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
- ir.navayemehr.util.AuthorizationFilter.doFilter(AuthorizationFilter.java:55)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement