title: jsf login page redirect error
body: <p>i am developing jsf using primefaces and jpa, and my screen is not redirecting to main page still exist in login page without display.</p>
  
  <p>My web.xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;Cation&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;login.xhtml&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
      &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;javax.servlet.jsp.jstl.fmt.localizationContext&lt;/param-name&gt;
      &lt;param-value&gt;resources.application&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
      &lt;description&gt;State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2&lt;/description&gt;
      &lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
      &lt;param-value&gt;client&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
      &lt;description&gt;
      This parameter tells MyFaces if javascript code should be allowed in
      the rendered HTML output.
      If javascript is allowed, command_link anchors will have javascript code
      that submits the corresponding form.
      If javascript is not allowed, the state saving info and nested parameters
      will be added as url parameters.
      Default is 'true'&lt;/description&gt;
      &lt;param-name&gt;org.apache.myfaces.ALLOW_JAVASCRIPT&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
      &lt;description&gt;
      If true, rendered HTML code will be formatted, so that it is 'human-readable'
      i.e. additional line separators and whitespace will be written, that do not
      influence the HTML code.
      Default is 'true'&lt;/description&gt;
      &lt;param-name&gt;org.apache.myfaces.PRETTY_HTML&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;org.apache.myfaces.DETECT_JAVASCRIPT&lt;/param-name&gt;
      &lt;param-value&gt;false&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
      &lt;description&gt;
      If true, a javascript function will be rendered that is able to restore the
      former vertical scroll on every request. Convenient feature if you have pages
      with long lists and you do not want the browser page to always jump to the top
      if you trigger a link or button action that stays on the same page.
      Default is 'false'
  &lt;/description&gt;
      &lt;param-name&gt;org.apache.myfaces.AUTO_SCROLL&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;org.apache.myfaces.webapp.StartupServletContextListener&lt;/listener-class&gt;
    &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>My faces-config.xml file</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;faces-config xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
      version="1.2"&gt;
      &lt;managed-bean&gt;
          &lt;managed-bean-name&gt;home&lt;/managed-bean-name&gt;
          &lt;managed-bean-class&gt;com.cation.action.LoginAction&lt;/managed-bean-class&gt;
          &lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt;      
      &lt;/managed-bean&gt;
      &lt;navigation-rule&gt;
          &lt;navigation-case&gt;
              &lt;from-outcome&gt;home_page&lt;/from-outcome&gt;
              &lt;to-view-id&gt;/pages/homePage.xhtml&lt;/to-view-id&gt;
          &lt;/navigation-case&gt;
      &lt;/navigation-rule&gt;
  &lt;/faces-config&gt; 
  </code></pre>
  
  <p>my login.xhtml</p>
  
  <pre><code>&lt;html xmlns="http://www.w3c.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"&gt;
  &lt;h:head&gt;
      &lt;link type="text/css" rel="stylesheet" href="themes/bluesky/skin.css" /&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;center&gt;
      &lt;p:panel header="Login Form" style="width: 350;"&gt;
          &lt;h:form&gt;
              &lt;h:panelGrid columns="2" cellpadding="2"&gt;
                  &lt;h:outputLabel for="#{home.username}" value="UserName"/&gt;
                  &lt;h:inputText value="#{home.username}" label="UserName"&gt;&lt;/h:inputText&gt;
                  &lt;h:outputLabel for="#{home.password}" value="Password"/&gt;
                  &lt;h:inputSecret value="#{home.password}"&gt;&lt;/h:inputSecret&gt;
                  &lt;h:commandButton type="submit" value="Login" action="#{home.validateUser}"&gt;&lt;/h:commandButton&gt;
              &lt;/h:panelGrid&gt;
          &lt;/h:form&gt;
      &lt;/p:panel&gt;
      &lt;div&gt;&lt;h:messages &gt;&lt;/h:messages&gt;&lt;/div&gt;
      &lt;/center&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>index.jsp file</p>
  
  <pre><code>&lt;jsp:forward page="login.xhtml"&gt;&lt;/jsp:forward&gt;
  </code></pre>
  
  <p>And my login action file</p>
  
  <pre><code>package com.cation.action;
  
  import java.util.List;
  
  import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  import javax.persistence.Query;
  
  import logon.Users;
  
  public class LoginAction {
  
      private String username;
  
      private String password;
  
      private static final String PERSISTENCE_UNIT_NAME = "Cation";
  
      private static EntityManagerFactory factory;
  
      @SuppressWarnings("unchecked")
      public String validateUser() throws Exception {
          factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
          EntityManager em = factory.createEntityManager();
          // Read the existing entries and write to console
          Query q = em.createQuery("SELECT u FROM Users u where u.Login='"+username+"'");
          List&lt;Users&gt; userList = q.getResultList();
          Users user = (Users) userList.get(0);
  
          if(user == null){
              return "error";
          }
          /*// Create new user
          em.getTransaction().begin();
          Users user = new Users();
          user.setName("Tom Johnson");
          user.setLogin("tomj");
          user.setPassword("pass");
          em.persist(user);
          em.getTransaction().commit();
  
          em.close();*/
          return "home_page";
      }
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  }
  </code></pre>
  
  <p>The problem is when i am logging using username and password it shows success in action but it is not redirecting to home page still exist in same page without any display and url shows like localhost:8080/Cation/login.xhtml</p>
  
  <p>Can anyone plz help me to solve it</p>