에서 문제가 발생했습니다. tomcat이 시작될 때 속성 파일을로드하려고합니다. servletContextListener를 사용하여 웹 응용 프로그램에 속성 파일 값을 가져올 수 있습니다. 하지만 한 번 웹 응용 프로그램에 로그인 할 때 속성 파일을 변경 한 후 동일한 값을 유지하고 싶습니다. 그러나 속성 파일의 값을 변경하고 시스템에 다시 로그인하면 새로운 값으로 변경됩니다. 동일한 값을 유지하려고합니다. 바람둥이 때 시작했다 .how 내가 이것을 구현할 수 있습니까?속성 파일
내 코딩은 내가 당신의 상황에 맞는 초기화가 한번 어떤 이유로 이상 호출되고 있음을 의심
import javax.servlet.*;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.*;
import java.util.ResourceBundle;
public final class sysProperties implements javax.servlet.ServletContextListener {
private static Properties props = new Properties();
private static String file_name = "com/util/contact.properties";
public addSystemProperties() {
}
public void contextInitialized(ServletContextEvent servletContextEvent) {
// Get the context
ServletContext servletContext = servletContextEvent.getServletContext();
// Set a context attribute
try {
// props.load(servletContext.getResourceAsStream(file_name));
props.load(getClass().getClassLoader().getResourceAsStream(file_name));
System.out.println(" Application X is starting");
servletContext.setAttribute("h1",props.getProperty("home.h1"));
servletContext.setAttribute("h2",props.getProperty("home.h2"));
System.out.println("h1"+servletContext.getAttribute("h1"));
System.out.println("h2"+ servletContext.getAttribute("h2"));
;
} catch (Exception e) {
System.out.println(" Error setting context attribute: " + e.getMessage());
}
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
// Get the context
ServletContext servletContext = servletContextEvent.getServletContext();
// Output the context variable we set earlier
System.out.println(" Application X is shutting down");
System.out.println(" Value of h1 is: " + servletContext.getAttribute("h1"));
System.out.println(" Value of h2 is: " + servletContext.getAttribute("h2"));
// Clean up (not really necessary as the context is being destroyed, but let's be neat)
servletContext.removeAttribute(props.getProperty("h1"));
servletContext.removeAttribute(props.getProperty("h2"));
}
}
가 확실 만든 사용자의 컨텍스트가 다시로드되지? 로그 아웃하고 system.context로 로깅이 다시로드되지 않으면 – Bozho
등록 정보 파일이 다시로드됩니다. – devuser