Olá galera, estou começando com jsf2 e criei um arquivo formulario.xhtml, sendo que quando chamo o mesmo no browser , ele me retorna :
HTTP Status 404 -
type Status report
message
description The requested resource () is not available.
Quanto inicio o servidor ele já da um erro também de ClassNotFoundExcpetion , segue a stacktrace :
Grave: Servlet /JFS2-JPA2 threw load() exception
java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5026)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5313)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1595)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1585)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Segue minha classe Java :
package br.com.jsf;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class NumeroAleatorio {
private int maximo;
private int numeroAleatorio;
public String geraNumeroAleatorio(){
this.numeroAleatorio = (int) (Math.random() * this.maximo);
return "resposta";
}
public int getMaximo() {
return maximo;
}
public void setMaximo(int maximo) {
this.maximo = maximo;
}
}
Meu arquivo formulario.xhtml :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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://java.sun.com/jsf/facelets"
xmlns:h = "http://java.sun.com/jsf/html"
xmlns:f = "http://java.sun.com/jsf/core" >
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Teste JSF2</title>
</h:head>
<h:body>
<h:form>
<h:outputLabel value= "Numero Máximo :"></h:outputLabel>
<h:inputText value= "#{numeroAleatorioBean.maximo}"></h:inputText>
<h:commandButton value = "Gera Número Aleatório" action="#{numeroAleatorioBean.geraNumeroAleatorio}"></h:commandButton>
</h:form>
</h:body>
</html>
Meu arquivo resposta.xhtml :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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://java.sun.com/jsf/facelets"
xmlns:h = "http://java.sun.com/jsf/html"
xmlns:f = "http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Teste JSF2</title>
</h:head>
<h:body>
<h:outputText value= "#{numeroAleatorioBean.numeroAleatorio}"></h:outputText>
</h:body>
</html>