PrettyFacesのようなフィルターベースのサーブレット拡張機能を使用してそれを実現することができます。
使い方は簡単で、優れたドキュメントと例がありますが、ケースを説明するには、次のようにすることができます。
- prettyfaces.jar をダウンロードして、クラスパスに追加します。通常
/WEB-INF/libフォルダ。
- URL マッピングを含む pretty-config.xml ファイルを
/WEB-INFフォルダーに追加します。
pretty-config.xml ファイルの例:
<?xml version="1.0" encoding="UTF-8"?>
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.3 http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd">
<url-mapping id="home">
<pattern value="/home" />
<view-id value="/home.xhtml" />
</url-mapping>
</pretty-config>
コントローラーからこのマッピングにリダイレクトするには、pretty:+のような文字列を使用する必要がありますurl-mapping-id。
コントローラー Bean の例:
@ManagedBean
@ViewScoped
public class HomeBean
{
public String goHome()
{
return "pretty:home";
}
}
それでおしまい。リクエストを発行するたびに、PrettyFaces フィルターが URL マッピング パターンを検出する/homeと、ビュー IDhome.xhtmlが表示されますが、URL はそのまま/homeです。かわいい。
また、提案として、welcome-file-list追加できるのはindex.html.
web.xml のウェルカム ファイル リスト タグの例:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
そして、このような index.html ファイルをアプリケーションのルート フォルダーに追加します。
index.html ファイルの例:
<!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">
<head>
<title>My Application</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="0;url=/myapplication/home" />
</head>
<body>
<h3>Loading...</h3>
</body>
</html>
こうすることで、誰かがあなたのアプリケーションをリクエストするたびに、読み込みの速いページが表示され、 にリダイレクトされ/homeます。
お役に立てば幸いです。