求javaweb的网址过滤器例编
给你讲讲实现的步骤:
(1)定义一个接口或者实体类,用户登录后在session绘画中建立一个属性,取名:USERINFO;
(2)在过滤器中读取该变量,你就可以任意判断了
下面是模拟代码:
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
if (debug) {
log("CheckLogin:doFilter()");
}
doBeforeProcessing(request, r...全部
给你讲讲实现的步骤:
(1)定义一个接口或者实体类,用户登录后在session绘画中建立一个属性,取名:USERINFO;
(2)在过滤器中读取该变量,你就可以任意判断了
下面是模拟代码:
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
if (debug) {
log("CheckLogin:doFilter()");
}
doBeforeProcessing(request, response);
HttpServletRequest req = (HttpServletRequest)request;
HttpSession session = tSession();
//没有发现需要的会话变量
if( tAttribute(this。
SESSION_USERINFO_NAME) == null){
HttpServletResponse res = (HttpServletResponse)response;
ndRedirect(this。
loginPage);
}
Throwable problem = null;
try {
Filter(request, response);
} catch (Throwable t) {
// If an exception is thrown somewhere down the filter chain,
// we still want to execute our after processing, and then
// rethrow the problem after that。
problem = t;
log( tMessage());
}
doAfterProcessing(request, response);
// If there was a problem, we want to rethrow it if it is
// a known type, otherwise log it。
if (problem != null) {
if (problem instanceof ServletException) {
throw (ServletException) problem;
}
if (problem instanceof IOException) {
throw (IOException) problem;
}
sendProcessingError(problem, response);
}
}。
收起