この例外が発生する1週間前に、JSFアプリの作成を開始したため、JSFは初めてです。
java.lang.RuntimeException: Cannot find FacesContext
EclipseINDIGOを使用しています
私はURLパターン/faces/*、faces/HelloWorld.jsp、jsf/HelloWorld.jspを試してみましたが、いつどのURLを使用する必要があるかを誰かに教えてもらえますか... ??
私の
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>
私の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>
私のマネージド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>