JSF2.0+JPA2.0+eclipse 構築編:FacesServletを動かす
さていよいよJSFの動作に挑戦します。私にとっては未知の領域。JSFの勉強も並行してやります。
まずはFacesServletの登録から。
web.xmlにFacesServletを登録
WebContent/WEB-INFの下に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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>jsf</display-name> <servlet> <servlet-name>JSFServlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>JSFServlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/index.xhtml</welcome-file> </welcome-file-list> </web-app>
これだけ。
トップページ(index.xhtml)を作成
テンプレートはxhtmlを使います。理由は、目にしているチュートリアルがどれもxhtmlで書かれているから。
中身はまずはかんたんに。
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" > <head> <meta charset="UTF-8" /> <title>JSF 2.0</title> </head> <body> <span jsfc="h:outputText">Hello,JSF!</span> </body> </html>
さて下のURLにアクセスしてみましょう。
http://localhost:18080/
参考ページ
英語だけど情報量は多い。今のところここのチュートリアルに沿って行くつもり。
http://www.coreservlets.com/JSF-Tutorial/jsf2/
次は
とりあえずFacesServletは動きました。
でもまだ単にxhtmlを表示しているだけです。次はWebアプリのアプリたるゆえん、動的なページを作ります。