?? loginfilter.java
字號(hào):
package com.sevenEleven.servlet;
// ==================== Program Discription =====================
// 程序名稱(chēng):示例14-8 : LoginFilter.java
// 程序目的:學(xué)習(xí)使用登錄過(guò)濾器
// ==============================================================
import javax.servlet.FilterChain;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.FilterConfig;
public class LoginFilter implements Filter
{
static String LOGIN_PAGE="index.jsp";
static String ERR_Page="../error500.jsp";
/**
* @uml.property name="filterConfig"
* @uml.associationEnd
*/
protected FilterConfig filterConfig;
public void doFilter(final ServletRequest req,final ServletResponse
res,FilterChain chain)throws IOException,ServletException
{
HttpServletRequest hreq = (HttpServletRequest)req;
// HttpServletResponse hres = (HttpServletResponse)res;
String isLog=(String)hreq.getSession().getAttribute("isLog");
if((isLog!=null)&&((isLog.equals("true"))||(isLog=="true")))//檢查是否登錄
{
chain.doFilter(req,res);
return ;
}
else{
hreq.getRequestDispatcher(ERR_Page).forward(req, res);
//hres.sendRedirect(ERR_Page);//如果沒(méi)有登錄,把視圖派發(fā)到錯(cuò)誤頁(yè)面
}
}
public void destroy()
{
this.filterConfig=null;
}
public void init(FilterConfig config)
{
this.filterConfig=config;
}
/**
* @param filterConfig
* @uml.property name="filterConfig"
*/
public void setFilterConfig(final FilterConfig filterConfig)
{
this.filterConfig=filterConfig;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -