Reputation: 163
How you might be able to read from the post title my question will be pretty newbish. I try to understand how to get JSF working with Eclipse and I tried to get a nice and famous Hello world running.
As a template I used the code from the Oracle Java EE 6 Book.
I created this ManagedBean - Hello.java in package de.kuntze
package de.kuntze;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class Hello {
final String world = "Hello World!";
public String getWorld(){
return world;
}
}
Can't get any easier... I use this with the following site to pair with - beanhello.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Facelets Hello World</title>
</h:head>
<h:body>
#{hello.world}
</h:body>
</html>
Also pretty easy... Here comes the code for 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" 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" version="3.0">
<display-name>CopyCat</display-name>
<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>
</web-app>
I let this run on the Tomcat 7 server I integrated with Eclipse and the output looks fine for me so far - if I can serve any logging details let me know!
The project's name is "CopyCat" and I expected it to see the managed Bean on my
http://localhost:8080/CopyCat/hello
but it gives me an 404 error same as the URL
http://localhost:8080/CopyCat/
and
http://localhost:8080/hello.
Am I just too stupid to see where my code goes or did I miss something? I know this question is very low level but I just don't get it and don't want to start coding with an existing project - which was already suggested to me :-/
Greetings and thanks in advance for any answers
André
UPDATE and somehow a solution
Altogether the solution for the problem was using another URL:
http://localhost:8080/CopyCat/faces/beanhello
Using tomcat with eclipse gave me some errors (see below) and here are two things I can suggest so far (btw: The JSTL.jar was not necessary for that):
a) Use the Eclipse workspace by coreservlets (http://www.coreservlets.com/JSF-Tutorial/jsf2/#Getting-Started) as a starting environment.
b) Change the URL-pattern to *.jsf
and reach the code with the URL
http://localhost:8080/HelloWorld/beanhello.jsf
Hope this helps if you are in a similar situation.
Upvotes: 2
Views: 6376
Reputation: 37051
try http://localhost:8080/CopyCat/faces/beanhello
cause your page name is beanhello.xhtml
and your servlet-mapping url-pattern is /faces/*
regarding your exception
read this answer by BalusC Exception java.lang.NoClassDefFoundError in Dynamic Web Application, Eclipse, JSF
Upvotes: 1