📄 privilegefilter.java
字号:
/**
*
*/
package cn.bway.struts.filter;
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;
import org.apache.log4j.Logger;
import cn.bway.common.WebConstant;
/**
* @author Kson
*
*/
public class PrivilegeFilter implements Filter {
private static Logger log = Logger.getLogger(PrivilegeFilter.class);
private final static String FILTERERRORRETURNPAGE = "filter.error";
private final static String FILTERERRORFINAL = "filter.finalError";
private FilterConfig config = null;
protected String encoding = null;
protected boolean ignore = true;
protected FilterConfig filterConfig = null;
/* (non-Javadoc)
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
*/
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
config = arg0;
this.encoding = arg0.getInitParameter("encoding");
String value = arg0.getInitParameter("ignore");
if (value == null) {
this.ignore = true;
} else if (value.equalsIgnoreCase("true")) {
this.ignore = true;
} else if (value.equalsIgnoreCase("yes")) {
this.ignore = true;
} else {
this.ignore = false;
}
}
/* (non-Javadoc)
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
// TODO Auto-generated method stub
String resultValue = null;
try {
String encoding = selectEncoding(arg0);
if (encoding != null) {
arg0.setCharacterEncoding(encoding);
}
resultValue = UserPrivilege.judgePrivilege((HttpServletRequest)arg0);
} catch (Exception e){
// TODO Auto-generated catch block
log.error(e.getMessage());
try{
resultValue = WebConstant.Filter;
}
catch(Exception ex){
resultValue = FILTERERRORFINAL;
arg0.setAttribute("error","filter key: " + FILTERERRORRETURNPAGE);
ex.printStackTrace();
}
}
if(resultValue == null){
arg2.doFilter(arg0,arg1);
}else{
log.info("\n get the resultValue == " +resultValue +"\n");
arg0.getRequestDispatcher(resultValue).forward(arg0,arg1);
}
}
/* (non-Javadoc)
* @see javax.servlet.Filter#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
this.encoding = null;
this.filterConfig = null;
this.config=null;
}
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -