Hi Leute,
ich will JSF lernen und habe mir, als Einführung, das Beispiel von der Seite JSF Hello World Example on Eclipse and Tomcat - JEE
vorgenommen.
Habe den Code aus dem Beispiel 1:1 abgeschrieben.
Wenn ich den Code jedoch ausführen möchte, bekomme ich eine 404 Fehlermeldung mit der Beschreibung
The requested resource (/pages/HelloWorldJSF.jsf) is not available.
hier erstmal meine Bean:
jetzt die beiden JSP Seiten HelloWorldJSF.jsp und HelloWorldResult.jsp, die sich im Ordner /WebContent/pages befinden.
meine WEB-xml Datei die sich im Ordner WebContent/WEB-INF befindet.
hier die faces-config Datei die sich im selben Ordner wie die WEB.xml Datei befindet.
hier die index.jsp die schliesslich ausgeführt wird und das Request an die HelloWorldJSF.jsp weiterleitet
Würde mich wirklich freuen, falls mir jemand helfen könnte.
Weis echt nicht mehr weiter.
Gruss!
ich will JSF lernen und habe mir, als Einführung, das Beispiel von der Seite JSF Hello World Example on Eclipse and Tomcat - JEE
vorgenommen.
Habe den Code aus dem Beispiel 1:1 abgeschrieben.
Wenn ich den Code jedoch ausführen möchte, bekomme ich eine 404 Fehlermeldung mit der Beschreibung
The requested resource (/pages/HelloWorldJSF.jsf) is not available.
hier erstmal meine Bean:
Java:
package myHomepage;
public class HelloWorldBean {
private String firstName;
private String lastName;
private String getFirstName() {
return firstName;
}
private void setFirstName(String firstName) {
this.firstName = firstName;
}
private String getLastName() {
return lastName;
}
private void setLastName(String lastName) {
this.lastName = lastName;
}
public String getCompleteName(){
return this.firstName+" "+this.lastName;
}
public String sayHelloWorld(){
return "succes";
}
}
jetzt die beiden JSP Seiten HelloWorldJSF.jsp und HelloWorldResult.jsp, die sich im Ordner /WebContent/pages befinden.
Java:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!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>Hello World JSF</title>
</head>
<body>
<f:view>
<p>
<h:message for="firstName" id="errors" style="color:red"></h:message>
<h:message for="lastName" id="errors1" style="color:red"></h:message>
</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>
</body>
</html>
Java:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!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>Hello World Result</title>
</head>
<body>
<f:view>
<h:form>
<h:outputText value="Complete Name is #{helloWorldBean.completeName}"></h:outputText>
</h:form>
</f:view>
</body>
</html>
meine WEB-xml Datei die sich im Ordner WebContent/WEB-INF befindet.
Java:
<?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>ApressJSF</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>/jsf/*</url-pattern>
</servlet-mapping>
<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>
</web-app>
hier die faces-config Datei die sich im selben Ordner wie die WEB.xml Datei befindet.
Java:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
<managed-bean-name>helloWorldBean</managed-bean-name>
<managed-bean-class>myHomepage.HelloWorldBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<display-name>HelloWorldJSF</display-name>
<from-view-id>/pages/HelloWorldJSF.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/pages/HelloWorldResult.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
hier die index.jsp die schliesslich ausgeführt wird und das Request an die HelloWorldJSF.jsp weiterleitet
Java:
<%@ page session="false" contentType="text/html;charset=utf-8"%>
<% response.sendRedirect("/pages/HelloWorldJSF.jsf"); %>
Würde mich wirklich freuen, falls mir jemand helfen könnte.
Weis echt nicht mehr weiter.
Gruss!