JSF 2.0 Navigation system Not Working with .jsp extension

428 views Asked by At

I have used JSF2.0 for the automatic Navigation System .I have a simple login page and when i clicked on the login Button then the method of the corresponding Bean class has called but it won't navigate to home.jsp page when i change the extension from .jsp to xhtml then it worked. What is the problem with .jsp extension.

LoginBean.java

public class LoginBean implements Serializable {
private static final long serialVersionUID = 1L;
private String uname;
private String password;


public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getUname() {
    return uname;
}

public void setUname(String uname) {
    this.uname = uname;
}

public String loginProject() {
     System.out.println("hello i am called ");
     System.out.println(uname);
     System.out.println(password);
        return "home";
    }
}

===============
login.xhtml

    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Colonial Inn</title>
</h:head>
<h:body>
<div align="center">
    <h:form id="loginForm">


        <p:growl id="msg" showDetail="true" life="3000" />
        <p:panel header="Login" style="width: 360px,margin-left:200px;">

            <h:panelGrid id="loginPanel" columns="2">

                <h:outputText value="Username" />

                <p:inputText id="username" value="#{loginBean.uname}"
                    required="true">

                </p:inputText>

                <p:spacer></p:spacer>

                <p:message for="username"></p:message>

                <h:outputText value="Password" />

                <p:password id="password" value="#{loginBean.password}"
                    feedback="false" required="true"></p:password>

                <p:spacer></p:spacer>

                <p:message for="password"></p:message>

                <p:spacer></p:spacer>

                <h:commandButton action="#{loginBean.loginProject}" value="Login"></h:commandButton>

            </h:panelGrid>

        </p:panel>

    </h:form>
    </div>

</h:body>

</html>

===================
Web.xml

 <?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"
    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">
    <display-name>NewCalonialinn</display-name>
    <welcome-file-list>
        <welcome-file>index.html</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>*.do</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-config.xml</param-value>
    </context-param>


    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>

================
home.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Insert title here</title>
</head>
<body>
<h1>Welcome to home page </h1>
</body>
</html>
1

There are 1 answers

0
BalusC On BEST ANSWER

What is the problem with .jsp extension.

It's deprecated since JSF 2.0.

Just stick to .xhtml extension.

See also: