創(chuàng)新互聯(lián)www.cdcxhl.cn八線動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買多久送多久,劃算不套路!
后臺(tái)管理頁(yè)面往往需要登錄才可以進(jìn)行操作,這時(shí)就需要Seession來(lái)記錄登錄狀態(tài)
要實(shí)現(xiàn)起來(lái)也是非常簡(jiǎn)單,只需要自定義一個(gè)HandlerInterceptor就行了
自定義的HandlerInterceptor也只有短短幾行代碼
public class LoginInterceptor implements HandlerInterceptor { @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object obj, Exception err) throws Exception { } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object obj, ModelAndView mav) throws Exception { } @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception { //獲取session里的登錄狀態(tài)值 String str = (String) request.getSession().getAttribute("isLogin"); //如果登錄狀態(tài)不為空則返回true,返回true則會(huì)執(zhí)行相應(yīng)controller的方法 if(str!=null){ return true; } //如果登錄狀態(tài)為空則重定向到登錄頁(yè)面,并返回false,不執(zhí)行原來(lái)controller的方法 response.sendRedirect("/backend/loginPage"); return false; } }
網(wǎng)站欄目:JavaWeb使用Session和Cookie實(shí)現(xiàn)登錄認(rèn)證-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://aaarwkj.com/article26/dohjcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、建站公司、網(wǎng)站內(nèi)鏈、網(wǎng)站改版、網(wǎng)站設(shè)計(jì)、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容