HelloWorldServlet.java の doGet メソッドに以下を含む単純な Hello World Servlet を Eclipse で作成しました。
PrintWriter writer = response.getWriter();
String hello = PropertyLoader.bundle.getProperty("hello");
writer.append(hello);
writer.flush();
PropertyLoader は、次のことを行うサーブレットと同じパッケージ内の単純なクラスです。
public class PropertyLoader {
public static final Properties bundle = new Properties();
static {
InputStream stream = null;
URL url = PropertyLoader.class.getResource("/helloSettings.properties");
stream = new FileInputStream(url.getFile());
bundle.load(stream);
}
}//End of class
次の 1 行のコンテンツを含む helloSettings.properties というファイルを /WebContent/WEB-IND/classes に配置しました。
hello=Hello Settings World
プロジェクトにTomcat 6.0を追加してEclipseで実行すると、正常に印刷されます
Webブラウザに「Hello Settings World」。
ただし、プロジェクトを war ファイルとしてエクスポートし、手動で .../Tomcat 6.0/webapps に配置すると、結果として「null」が表示されます。
クラスパス/クラスローダーの設定に問題がありますか? 許可?他の構成ファイルはありますか?helloSettings.properties ファイルが WEB-INF/classes フォルダーにあるという事実を知っています。
何か助けはありますか?