- Web.xml -
<filter>
<filter-name>Session Check</filter-name>
<filter-class>sdw.framework.util.SessionCheckFilter</filter-class>
<init-param>
<param-name>LOGOUT_URL</param-name>
<param-value>/logoff.jsp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Session Check</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
- Java -
package sdw.framework.util;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
public class SessionCheckFilter implements Filter {
private String logoutUrl = null;
public void init(FilterConfig filterconfig) throws ServletException {
if (logoutUrl == null) {
logoutUrl = filterconfig.getInitParameter("LOGOUT_URL");
}
}
public void doFilter(ServletRequest servletrequest, ServletResponse servletresponse, FilterChain filterchain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletrequest;
String page = request.getRequestURI().substring(request.getRequestURI().lastIndexOf("/") + 1);
System.out.println(LoginHelper.isLogin(request));
System.out.println(Environment.getInstance().get("no.session.jsp").indexOf(page) == -1);
if (!LoginHelper.isLogin(request) && Environment.getInstance().get("no.session.jsp").indexOf(page) == -1) {
servletrequest.setAttribute("exception", new Exception("정상적으로 로그인하지 않았거나 세션이 종료되었습니다."));
servletrequest.getRequestDispatcher("//." + logoutUrl).forward(servletrequest, servletresponse);
} else {
filterchain.doFilter(servletrequest, servletresponse);
}
}
public void destroy() {
/* empty */
}
}
- Environment.java -
package sdw.framework.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
public class Environment implements Cloneable {
private static Environment mInstance = null;
private static Hashtable mBundles = null;
private static Hashtable mChecks = null;
private static String defaultLoadPath = null;
private Properties mCurrent = null;
private String mName = null;
private Environment() throws Exception {
if (mBundles == null) {
mBundles = new Hashtable();
}
if (mChecks == null) {
mChecks = new Hashtable();
}
}
public static Environment getInstance() {
return getInstance("default");
}
public static synchronized Environment getInstance(String name) {
Environment env = null;
try {
System.out.println(mInstance);
if (mInstance == null) {
mInstance = new Environment();
}
env = (Environment) mInstance.clone();
System.out.println(defaultLoadPath);
if (defaultLoadPath != null) {
if (!mBundles.containsKey(name)) {
loadFile(name);
}
env.setResource(name);
if (env.isModified()) {
//env.refresh();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return env;
}
private static void loadFile(String name) throws Exception {
File file = new File(defaultLoadPath, name + ".properties");
Properties props = new Properties();
props.load(new FileInputStream(file));
mBundles.put(name, props);
mChecks.put(name, new Long(file.lastModified()));
}
private void setResource(String name) {
mName = name;
mCurrent = (Properties) mBundles.get(name);
}
private boolean isModified() {
File file = new File(defaultLoadPath, mName + ".properties");
long newT = file.lastModified();
return (newT > ((Long) mChecks.get(mName)).longValue());
}
public String get(String name) {
return mCurrent.getProperty(name) == null ? "" : mCurrent.getProperty(name);
}
public void put(String name, String value) {
mCurrent.put(name, value);
}
public void remove(String name) {
mCurrent.remove(name);
writeFile();
}
public Enumeration getKeys() {
return mCurrent.keys();
}
public Properties getProperties() {
return mCurrent;
}
public void writeFile() {
FileOutputStream out = null;
try {
File file = new File(defaultLoadPath, mName + ".properties");
out = new FileOutputStream(file);
mCurrent.store(out, null);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void setDefaultLoadPath(String path) {
defaultLoadPath = path;
}
public String getDefaultLoadPath() {
return defaultLoadPath;
}
public String getName() {
return mName;
}
}
- default.properties -
log.level=DEBUG
log.file=D:/Temp/admin.log
connectionTimeout=600000
upload.pic.path=D:/Temp
upload.board.path=D:/workspace/workspace_aa2/aa2/WebContent/images/upload
upload.gos.path=D:/Temp
ftp.gos.user=aa
ftp.gos.password=aa
ftp.gos.port=21
ftp.gos.path=/Interface/aa
window.title=%s\uc790\ub3d9\ucc28 :: aa2
no.session.jsp=index.jsp;Login.jsp;logoff.jsp;Login_json;IdPop.jsp;Id_json.jsp;Password.jsp;PasswordPop.jsp
no.session.service=sdw.comm.service.LoginWb;sdw.comm.service.LogWb
session.timeout=480
'Xml' 카테고리의 다른 글
[Xml] Web.xml (0) | 2011.03.02 |
---|---|
[Xml] Ant - FTP 파일 업로드 하기 (0) | 2010.12.22 |
[Xml] Web.xml - Filter (0) | 2010.12.08 |
[Xml] JDOM 설치와 (JAVA로 XML 문서만들기/추가하기) (0) | 2010.12.07 |
[Xml] 오라클 쿼리로 바로 xml생성 하기 (0) | 2010.12.07 |