3
<%! FxDataModel FxDataModel = null;
public void jspInit() {
Properties fxProp = new Properties();
ServletContext ctx = getServletContext();
String path = ctx.getRealPath("/WEB-INF/fxRates.csv");
fxProp.getProperty(path);
try{
FileInputStream fis = new FileInputStream(ctx.getRealPath(ctx.getInitParameter(FxDataModel.FX_PRP_FILE_NAME)));
// Now that you have fis you can load properties.
fxProp.load(fis);
// Now, you are done with fis so close it
fis.close();
}catch (IOException e) {}
FxDataModel = new FxDataModel(fxProp);
}
%>
看看我在NetBeans中的代碼,一切都很正常。但是,當我運行它時,我得到一個HTTP狀態500錯誤。當我問我關於如何解決它的教授,他告訴我,展開文件名,重新插入屬性對象
「顯然,fxRates.csv是不是因爲你沒有文件 名擴大到與getRealPath和絕對路徑它重新插入 屬性對象fxProp。「
我不完全確定我的項目中有哪些其他代碼需要添加,但我有一種感覺,錯誤在本節中。我究竟做錯了什麼?
你*應該*必須使用Servlet來讀取'.properties'文件。爲什麼使用'ctx.getInitParameter'方法?只需嘗試'fxProp.load(new FileInputStream(path));' – adatapost
向我們展示您獲得的錯誤500的堆棧跟蹤。 –