TagSupport를 확장하는 클래스 파일이 있습니다. 여기에서 속성 파일을 읽지 만 작동하지 않습니다. getResourceAsStream null을 반환하는 것 같아요.TagSupport로 null을 반환하는 getResourceAsStream
나는 bith 시스템에서 폭발 된 war 파일을 사용하고 있습니다.
코드 :
공용 클래스 MyTag는 통상의 경우, TagSupport {
private int getUsers() { ServletContext servletContext = pageContext.getServletContext(); InputStream in = pageContext.getServletContext().getResourceAsStream("/WEB-INF/app.properties"); Properties properties = new Properties(); properties.load(in); int users= Integer.parseInt(properties.getProperty("users")); return users; }
}
이 코드는 내 PC에서 작동을 확장하지만, 테스트 시스템을 작동 나던. 나는 다음과 같은 예외가 :
하여 java.lang.NullPointerException 오류 [STDERR] java.util.Properties $ LineReader.readLine (Properties.java:418) java.util.Properties에서 오류 [STDERR]에서 .load0 (Properties.java:337) ERROR [STDERR]은 java.util.Properties.load (Properties.java:325)에서
그건 또 다른 일입니다. 하지만 그것은 dev 시스템에서 작동하고 테스트에서는 작동하지 않는 이유는 무엇입니까? – JazB
두 시스템 (OS, JDK 버전, 응용 프로그램 서버 등)에 대해 알지 못해도 말하기가 어렵습니다. 그러나 일반적으로 속성 파일과 기타 자원은'/ WEB-INF/classes'에 있습니다. – mthmulders
감사합니다. 그래서 내 코드에 문제가있다. getServletContext를 사용하면 컨텍스트 루트를 기준으로 리소스를로드 할 수 있습니다. – JazB