Wrong pages navigation - jsf

My web application includes 3 pages:
index.xhtml
welcome.xhtml
nextround.xhtml
I have two javaBean classes:
1.webTimeBean
2.userBean
the webtimeBean class is #ApplicationScoped.
the userBean class is #SessionScoped.
I also have class for SQL requests and User class for user information.
I have a navigation issue.
After the user login (index.xhtml) the welcome page loads correctly with data from database.
Then the user can click on a next round link but instead to navigate to nextround.xjtml the application send him back to the index.xhtml page.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"/>
<h:head>
<title>Web TIme : A simple example Title</title>
<meta http-equiv="refresh" content="60"/>
</h:head>
<h:body>
<div class="w3-container w3-light-grey w3-border">
<p>Today : #{webTimeBean.time}</p>
</div>
<h:form>
<br></br>
<h:inputText value="#{userBean.email}" class="w3-input" />
<h:inputText value="#{userBean.password}" class="w3-input" />
<h:commandButton value="Log In" class="w3-btn-block w3-teal" action="#{userBean.verifyLogin()}" />
</h:form>
</h:body>
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"/>
<h:head>
<title>Goalim Game </title>
<meta http-equiv="refresh" content="300"/>
</h:head>
<h:body>
<div class="w3-container w3-light-grey w3-border">
<p>Today : #{webTimeBean.time}</p>
</div>
<table class="w3-table w3-bordered w3-striped">
<tr>
<th>User Name</th>
<th>Score</th>
</tr>
<ui:repeat var="elem" value="#{userBean.tblScore}" >
<tr>
<td>
<h:outputText value="#{elem.userName}" />
</td>
<td>
<h:outputText value="#{elem.totalPoints}" />
</td>
</tr>
</ui:repeat>
</table>
<form>
<h:commandButton value="Next Round" class="w3-btn-block w3-teal" action="/nextround.xhtml" />
</form>
</h:body>
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"/>
<h:head>
<title>Web TIme : A simple example Title</title>
<meta http-equiv="refresh" content="60"/>
</h:head>
<h:body>
<div class="w3-container w3-light-grey w3-border">
<p>Today : #{webTimeBean.time}</p>
<p>Hello : #{userBean.userName}</p>
</div>
</h:body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<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/index.xhtml</welcome-file>
</welcome-file-list>
<resource-ref>
<description>postgress database</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>

Related

JSF page template --html meta refresh is not working [duplicate]

This question already has an answer here:
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
(1 answer)
Closed 5 years ago.
Here's template
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="refresh" content="30">
<title><ui:insert name="title">Default Title</ui:insert></title>
<h:outputStylesheet library="css" name="jsfcrud.css"/>
</h:head>
<h:body>
<h1>
<ui:insert name="title">Default Title</ui:insert>
</h1>
<p>
<ui:insert name="body">Default Body</ui:insert>
</p>
</h:body>
</html>
here's a client
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/template.xhtml">
<ui:define name="title">
<h:outputText value="#{bundle.ListPhonerecordTitle}"></h:outputText>
</ui:define>
<ui:define name="body">
<h:form styleClass="jsfcrud_list_form">
<p:poll interval="10" listener="#{phonerecordController.prepareList}" update="#all" />
...
...
...
</h:form>
</ui:define>
</ui:composition>
</html>
When I run client page meta refresh is not working (refresh page every 30 seconds).
I tried putting meta refresh tag in template (inside h:head) but when client page is run it is not refreshing the page.
Should I try putting the meta refresh tag inside ui:composition tag in client page?
If I add an image inside h:body in template like this
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><ui:insert name="title">Default Title</ui:insert></title>
<h:outputStylesheet library="css" name="jsfcrud.css"/>
</h:head>
<h:body>
<h:graphicImage value = "resources/phonegirl1.PNG"/><br />
<h1>
<ui:insert name="title">Default Title</ui:insert>
</h1>
<p>
<ui:insert name="body">Default Body</ui:insert>
</p>
</h:body>
</html>
and try to open in client page image is not there. It's not visible when i run template page as well.
This may have the answer:
Template content not displaying
if i add a text "Hello World" in template like so
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><ui:insert name="title">Default Title</ui:insert></title>
<h:outputStylesheet library="css" name="jsfcrud.css"/>
</h:head>
<h:body>
Hello World!
<h1>
<ui:insert name="title">Default Title</ui:insert>
</h1>
<p>
<ui:insert name="body">Default Body</ui:insert>
</p>
</h:body>
</html>
every client page referring to template has Hello World written on its page.
But if I try the same in one of the client pages they don't work.

/enternameform.xhtml #17,59 value="#{register.firstName}": Target Unreachable, identifier 'register' resolved to null [duplicate]

This question already has answers here:
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
(18 answers)
Closed 6 years ago.
I am new to jsf and am getting a parse error when running a simple form. The error says "/enternameform.xhtml #17,59 value="#{register.firstName}": Target Unreachable, identifier 'register' resolved to null"
My code is below
enternameform.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>registration form</title>
<link href="./css/styles.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<div align="center">
<h1 class="title">Enter Name and Register</h1>
<br/>
<fieldset>
<legend>Please Enter Name here</legend>
<h:form>
<!-- Your form elements here -->
First Name: <h:inputText value="#{register.firstName}"/> <br/>
Last Name: <h:inputText value="#{register.lastName}"/><br/>
<h:commandButton value="go ahead" action="#{register.fullName}"/>
</h:form>
</fieldset>
</div>
</h:body></html>
Register.java
package registrationform;
import javax.faces.bean.ManagedBean;
#ManagedBean
public class Register {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String fullName (){
if(isMissing(firstName)|| isMissing(lastName)){
return("missing");
}else{
return("registrationsuccess");
}
}
private boolean isMissing(String name){
return (name.trim().isEmpty());
}
}
missing.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>missing</title>
<link href="./css/styles.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<h1 class="title">Please enter both First and Last Name to Register</h1>
Try again here
</h:body></html>
registrationsuccess.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>registrationsuccess</title>
<link href="./css/styles.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<h1 class="title">You have completed registration</h1>
First Name: #{register.firstName} <br/>
Last Name:#{register.lastName}
</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"
version="3.0">
<!-- The bare minimum needed for JSF 2.2 is a servlet 2.5 or later
declaration (this uses 3.0) and the mapping for the FacesServlet.
Setting PROJECT_STAGE to Development is highly recommended
during initial development so that you get more helpful
error messages. Whether you want server-side state saving
(default) or client-side is a more complicated question:
client-side uses more bandwidth but fewer server resources.
Client-side also helps to avoid the dreaded view expired exceptions.
From JSF 2 and PrimeFaces tutorial
at http://www.coreservlets.com/JSF-Tutorial/jsf2/
-->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (default). See JSF Specification section 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<!-- If you go to http://host/project/ (with no file name), it will
try index.jsf first, welcome.jsf next, and so forth.
-->
<welcome-file-list>
<welcome-file>enternameform.jsf</welcome-file>
<welcome-file>welcome.jsf</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Please let me know what I may be doing wrong here.
It has been fixed after restarting server n some edits

Facelet client does not use assigned facelet client

Hope you can help me with this trivial problem. I have created a facelet template like this:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet name="./css/default.css"/>
<h:outputStylesheet name="./css/cssLayout.css"/>
<title>Facelets Template</title>
</h:head>
<h:body>
<div id="top">
<ui:insert name="top"><h1>Super Cool App</h1></ui:insert>
</div>
<div id="content" class="center_content">
<ui:insert name="content">Content</ui:insert>
</div>
<div id="bottom">
<ui:insert name="bottom"><br/><br/>Powered by GlassFish & NetBeans</ui:insert>
</div>
</h:body>
</html>
Now I have a facelet client which is assigned to the template like below. However, when I remove the top and bottom part of the clients facelet, it should inherence the top and bottom stuff from the template, right? But it does not. Could you tell me, what I did wrong?
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<body>
<ui:composition template="./WEB-INF/templates/template.xhtml">
<ui:define name="content">
content
</ui:define>
</ui:composition>
</body>
</html>
Thanks in advance. See you along.

JSF form not shown

i want to implement a login page using jsf for that i wanted
to implement a form:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Login</title>
<link href="../resources/css/basic.css" type="text/css" rel="stylesheet" />
</h:head>
<h:body>
<div id="wrapper">
<ul id="menu">
<li id="menutab"><a class="link" href="../index.jsp">Home</a></li>
<li id="menutab"><a class="link" href="../jsf/list.jspx">Liste</a></li>
<li id="menutab"><a class="link" href="../servlets/DataServlet">Daten</a></li>
<li id="menutab"><a class="link" href="../servlets/ListMoviesServlet">Movies</a></li>
<li id="menutab"><a class="link" href="../servlets/ListPeopleServlet">People</a></li>
</ul>
<br></br>
<h2 id="title">Login</h2>
<h:form id="j_security_check">
<center>
<h:messages errorClass="errorMessage" infoClass="infoMessage" warnClass="warnMessage"></h:messages>
<h:panelGrid columns="2">
<h:outputText value="Username : "/>
<h:inputText id="j_username" value="#{loginBean.username}"/>
<h:outputText value="Password : "/>
<h:inputSecret id="j_password" value="#{loginBean.password}"/>
<h:commandButton value="Submit" action="#{loginBean.login}" type="submit"/>
</h:panelGrid>
</center>
</h:form>
</div>
</h:body>
</html>
The page is shown but the form defined here isnt shown. everything
after the title is just a white screen.
Why the form isnt rendered?
Ok i got it!
This is the jsf mapping in my web.xml:
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
As you see the url-pattern describes ".jspx"
So i have to call my jsf with "myjsf.jspx" instead of "myjsf.xhtml"
<login-config>
<auth-method>FORM</auth-method>
<realm-name>loginRealm</realm-name>
<form-login-config>
<form-login-page>/jsf/login.jspx</form-login-page>
<form-error-page>/jsf/error.jspx</form-error-page>
</form-login-config>
</login-config>

java.lang.RuntimeException: Cannot find FacesContext [duplicate]

This question already has an answer here:
java.lang.RuntimeException Cannot find FacesContext
(1 answer)
Closed 7 years ago.
I'm new to JSF as i have started creating JSF app one week before i'm getting this exception
java.lang.RuntimeException: Cannot find FacesContext
i'm using Eclipse INDIGO
I'have tried with url pattern /faces/*, faces/HelloWorld.jsp, jsf/HelloWorld.jsp
can anyone tell me that which url we have to use when...??
my
web.xml
<display-name>JSFTutorial</display-name>
<welcome-file-list>
<welcome-file>HelloWorld.jsp</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>/jsf/*</url-pattern>
</servlet-mapping>
my faces.config.xml
<?xml version="1.0" encoding="UTF-8"?>
<managed-bean>
<managed-bean-name>helloWorldBean</managed-bean-name>
<managed-bean-class>com.myhomepageindia.jsftutorial.web.bean.HelloWorldBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<display-name>HelloWorld</display-name>
<from-view-id>/HelloWorld.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/HelloWorldResult.jsp</to-view-id>
</navigation-case>
</navigation-rule>
my Managed bean
package com.myhomepageindia.jsftutorial.web.bean;
public class HelloWorldBean {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getCompleteName() {
return this.firstName + " " + this.lastName;
}
public String sayHelloWorld() {
return "success";
}
}
HelloWorld.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%#taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%#taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello World</title>
</head>
<body>
<%
try {
%>
<f:view>
<p>
<h:message id="errors" for="firstName" style="color:red" />
<h:message id="errors1" for="lastName" style="color:red" />
</p>
<h:form>
<h:outputText value="First Name"></h:outputText>
<h:inputText id="firstName" value="#{helloWorldBean.firstName}"
required="true"></h:inputText>
<h:outputText value="Last Name"></h:outputText>
<h:inputText id="lastName" value="#{helloWorldBean.lastName}"
required="true"></h:inputText>
<h:commandButton action="#{helloWorldBean.sayHelloWorld}"
value="Get Complete Name"></h:commandButton>
</h:form>
</f:view>
<%
} catch (Exception e) {
out.println(e);
}
%>
</body>
Based in your web.xml configuration, you should call the pages under "/jsf/" to made them work with the Faces Servlet. There are two possible solutions for this:
Make sure you're accesing your pages like this http://your.domain.com/YourProject/jsf/anyPAge.jsp
Try changing the configuration in your web.xml to something like
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Then access your page like http://your.domain.com/YourProject/jsf/anyPAge.jsf
Note for the last option: if you're using JSF 1.x, you must not use *.jsp as the url-pattern, it will give you a huge error explained here: Help with JSF 1.2 + Jboss 5.1.0 (it doesn't mind if you'reusing Tomcat, you will have the same error). If you're using JSF 2.x, then there will be no problem, and you should be using Facelets (those pages with xhtml extension) as explained here: What is the difference between JSF and Facelets?
A very simple way to test if JSF is working in your project is to make this simple page:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%#taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%#taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello World</title>
</head>
<body>
<f:view>
<h:outputText value="Hello world!" />
</f:view>
</body>
</html>
If this page gives you errors, then there must be something else in your project or in your application server that is blocking the Faces Servlet.
Make sure you have all the correct Jars on your classpath.
Change the following things in your code:
Change your url-pattern in web.xml to *.jsf.
Wrap all your html code inside <f:view> tags
<%# page pageEncoding="UTF-8" %>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!doctype ... >
<f:view>
<html>
...
</html>
</f:view>
Now your URL should be:
localhost:8080/JSFTutorial/HelloWorld.jsf
Hope this helps!
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
What works for me is to just omit using the Taglib in my jsp file and move them into the html tag such as
<%# taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%# taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Simple jsp page</title></head>
<body>
<f:view>
<h:outputLabel value="Hello, world"/>
</f:view>
</body>
</html>
Becomes
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<head><title>Simple jsp page</title></head>
<body>
<f:view>
<h:outputLabel value="Hello, world"/>
</f:view>
</body>
</html>

Resources