0

I am new to JSF and starting to explore it and I have created a simple login application using jsf, when i try to run it via apache tomcat server, it is displaying fine in the browser but the problem is when i give the credentials and try to login it is displaying the correct content of the page but the URL is like this JSF_Sample_2/faces/Login.jsp and it has to be JSF_Sample_2/faces/Success.jsp and while displaying also it is showing only upto the application name like this JSF_Sample_2/

My web.xml is

<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>JSF_Sample_2</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>faces/Login.jsp</welcome-file>
  </welcome-file-list>
</web-app>

My faces-config.xml is

<?xml version="1.0" encoding="UTF-8"?>

<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"> <managed-bean>
        <managed-bean-name>loginFormBean</managed-bean-name>
        <managed-bean-class> 
            com.Lawrence.JSF.LoginFormBean
        </managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <from-view-id>/Login.jsp</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/Success.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>Failure</from-outcome>
            <to-view-id>/Failure.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>home</from-outcome>
            <to-view-id>/Login.jsp</to-view-id>
        </navigation-case>
    </navigation-rule> </faces-config>

My Managed Bean is

package com.Lawrence.JSF;

public class LoginFormBean 
{
    private String userName;
    private String passWord;

    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;
    }

    public String doLogin()
    {
        if(getUserName().equals("Lawrence") && getPassWord().equals("lawrence"))
        {
            return "success";
        }
        else
        {
            return "Failure";
        }   
    }

    public String logOut()
    {
        return "home";
    }
}

and in the success page as well as failure page i am using commandlink where action is given as loginformbean.logOut which takes back to the login page but that is also not working and i have written navigation rule in faces-config rule Please help me to solve this problems

user1791442
  • 11
  • 1
  • 4
  • 1
    Sorry, I disregarded initially that you were doing explicit navigation. Therefore, I deleted that comment. Add `` after `/Success.jsp` in the JSF configuration file to redirect instead of forwarding/dispatching. In case of implicit navigation, you could simply append `?faces-redirect=true` to the navigation case outcome here `return "success?faces-redirect=true";`. Why are they JSP pages, by the way? Are you using JSF1.x? You should not be interested in using this URL pattern, `/faces/*` unless you really happened to use JSF 1.x. – Tiny Apr 26 '15 at 05:44
  • Thanks dude it resolved my problem but i still face problem in using commandLink as well as when i initially start the application from eclipse it is showing the url as /JSF_Sample_2/ not as /JSF_Sample_2/login.jsp. Please help me in this – user1791442 Apr 26 '15 at 06:39
  • Maybe you should specify that page name via Right-click the project > Properties > "Run" . – Omar Apr 26 '15 at 07:06
  • 1
    `login.jsp` is a welcome file (as specified by `faces/Login.jsp`). A welcome file is a file which is served whenever the folder holding the welcome file itself is requested i.e. it is the default file to be served whenever the directory containing that file itself is requested. You are requesting the folder holding the welcome file through `/` in this case. You can only see `/JSF_Sample_2/login.jsp`, if you send a redirect from `/` to `/login.jsp` perhaps through a `` tag. – Tiny Apr 26 '15 at 08:42
  • Create a welcome file that does nothing but in an http meta redirect redirect to the page you want. And if using a good aaa framework should **not** be the login page – Kukeltje Apr 26 '15 at 10:19

0 Answers0