strust2自定義攔截器

1.創建一個攔截器類,繼承MethodFilterInterceptor類,實現doIntercept方法

package com.yqg.bos.web.interceptor;import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import com.yqg.bos.entity.User;
import com.yqg.bos.utils.CommonUtils;public class BosInterceptor extends MethodFilterInterceptor{//該攔截器功能為如果session中的用戶為空,跳轉到登錄界面。protected String doIntercept(ActionInvocation invocation) throws Exception {User user =  CommonUtils.getLoginUser();if(user == null) {
//如果user為空,跳回login.jsp界面,否則放行
return "login";}else {return invocation.invoke();}}}

package com.yqg.bos.utils;import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;import com.yqg.bos.entity.User;public class CommonUtils {public static HttpSession getSession() {return ServletActionContext.getRequest().getSession();}public static User getLoginUser() {return (User) getSession().getAttribute("loginUser");}
}

2.在struts.xml中配置該攔截器,并設置一個自定義攔截器棧作為默認攔截器棧。

  <interceptors>
<!--將自定義的攔截器注冊到struts中--> <interceptor name="bosInterceptor" class="com.yqg.bos.web.interceptor.BosInterceptor">
<!--除login方法之外的所有方法都被攔截--><param name = "excludeMethods">login</param></interceptor>
<!--自定義攔截器棧,并將自定義攔截器加入到棧中,還將struts默認的攔截器棧加入到自定義攔截器棧中--><interceptor-stack name="myStack"><interceptor-ref name="bosInterceptor"></interceptor-ref><interceptor-ref name="defaultStack"></interceptor-ref></interceptor-stack></interceptors>
<!--設置自定義攔截器棧為默認攔截器棧取代struts的默認攔截器棧defaultStack--><default-interceptor-ref name="myStack" />
<!--定義攔截結果--><global-results><result name="login">/login.jsp</result></global-results>

?

轉載于:https://www.cnblogs.com/yanqingguo/p/9827158.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388174.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388174.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388174.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Android Studio如何減小APK體積

最近在用AndroidStudio開發一個小計算器&#xff0c;代碼加起來還不到200行。但是遇到一個問題&#xff0c;導出的APK文件大小竟然達到了1034K。這不科學&#xff0c;于是就自己動手精簡APK。下面我們大家一起學習怎么縮小一個APK的大小&#xff0c;以hello world為例。 新建工…

js合并同類數組里面的對象_通過同類群組保留估算客戶生命周期價值

js合并同類數組里面的對象This is Part I of the two-part series dedicated to estimating customer lifetime value. In this post, I will describe how to estimate LTV, on a conceptual level, in order to explain what we’re going to be doing in Part II with the P…

C#解析HTML

第一種方法&#xff1a;用正則表達式來分析 [csharp] view plaincopy 轉自網上的一個實例&#xff1a;所有的href都抽取出來&#xff1a; using System; using System.Net; using System.Text; using System.Text.RegularExpressions; namespace HttpGet { c…

幫助開發人員學習

在瀏覽器中使用真實環境學習新技術 https://www.katacoda.com/ 轉載于:https://www.cnblogs.com/zuxing/p/9829143.html

【轉】SASS用法指南

SASS用法指南 阮一峰的&#xff0c;偏sass用法教程sass入門 偏實戰的基礎用法

com編程創建快捷方式中文_如何以編程方式為博客創建wordcloud?

com編程創建快捷方式中文Recently, I was in need of an image for our blog and wanted it to have some wow effect or at least a better fit than anything typical we’ve been using. Pondering over ideas for a while, word cloud flashed in my mind. &#x1f4a1;Us…

ETL技術入門之ETL初認識

ETL技術入門之ETL初認識 分類&#xff1a; etl2014-07-10 23:11 3021人閱讀 評論(2) 收藏 舉報數據倉庫商業價值etlbi目錄(?)[-] ETL是什么先說下背景知識下面給下ETL的詳細解釋定義現在來看下kettle的transformation文件一個最簡單的E過程例子windows環境 上圖左邊的是打開表…

ActiveSupport::Concern 和 gem 'name_of_person'(300?) 的內部運行機制分析

理解ActiveRecord::Concern&#xff1a; 參考:include和extend的區別&#xff1a; https://www.cnblogs.com/chentianwei/p/9408963.html 傳統的模塊看起來像&#xff1a; module Mdef self.included(base)# base(一個類)擴展了一個模塊"ClassMethods"&#xff0c; b…

Python 3.8.0a2 發布,面向對象編程語言

百度智能云 云生態狂歡季 熱門云產品1折起>>> Python 3.8.0a2 發布了&#xff0c;這是 3.8 系列計劃中 4 個 alpha 版本的第 2 個。 alpha 版本旨在更加易于測試新功能和 bug 修復狀態&#xff0c;以及發布流程。在 alpha 階段會添加新功能&#xff0c;直到 beta 階…

基于plotly數據可視化_如何使用Plotly進行數據可視化

基于plotly數據可視化The amount of data in the world is growing every second. From sending a text to clicking a link, you are creating data points for companies to use. Insights that can be drawn from this collection of data can be extremely valuable. Every…

關于Oracle實時數據庫的優化思路

關于實時數據庫的優化思路 背景 大概168個換熱站機組&#xff0c;每套機組將近400個點&#xff0c;整體有6萬多個點需要進行實時更新。數據庫里其中有一個監控參數表(yxjk_jkcs)&#xff0c;每一個點位屬性都在里面存放&#xff0c;其中有一個字段CS_VALUE 是存放被更新的實時…

【轉】使用 lsof 查找打開的文件

在 UNIX 環境中&#xff0c;文件無處不在&#xff0c;這便產生了一句格言&#xff1a;“任何事物都是文件”。通過文件不僅僅可以訪問常規數據&#xff0c;通常還可以訪問網絡連接和硬件。在有些情況下&#xff0c;當您使用 ls 請求目錄清單時&#xff0c;將出現相應的條目。在…

ESLint簡介

ESLint簡介 ESLint是一個用來識別 ECMAScript 并且按照規則給出報告的代碼檢測工具&#xff0c;使用它可以避免低級錯誤和統一代碼的風格。如果每次在代碼提交之前都進行一次eslint代碼檢查&#xff0c;就不會因為某個字段未定義為undefined或null這樣的錯誤而導致服務崩潰&…

數據科學與大數據是什么意思_什么是數據科學?

數據科學與大數據是什么意思Data Science is an interdisciplinary field that uses a combination of code, statistical analysis, and algorithms to gain insights from structured and unstructured data.數據科學是一個跨學科領域&#xff0c;它結合使用代碼&#xff0c;…

C#制作、打包、簽名、發布Activex全過程

一、前言 最近有這樣一個需求&#xff0c;需要在網頁上面啟動客戶端的軟件&#xff0c;軟件之間的通信、調用&#xff0c;單單依靠HTML是無法實現了&#xff0c;因此必須借用Activex來實現。由于本人主要擅長C#&#xff0c;自然本文給出了用C#實現的范例&#xff0c;本文的預期…

用Python創建漂亮的交互式可視化效果

Plotly is an interactive Python library that provides a wide range of visualisations accessible through a simple interface.Plotly是一個交互式Python庫&#xff0c;通過簡單的界面即可提供廣泛的可視化效果。 There are many different visualisation libraries avai…

CCF 201809-1 買菜

問題描述| 試題編號&#xff1a; | 201809-2 | | 試題名稱&#xff1a; | 買菜 | | 時間限制&#xff1a; | 1.0s | | 內存限制&#xff1a; | 256.0MB | 問題描述 小H和小W來到了一條街上&#xff0c;兩人分開買菜&#xff0c;他們買菜的過程可以描述為&#xff0c;去店里買一…

筆試題③

1.線程間通信 handler機制 2.AsyncTask 異步任務 3.HandlerThread 子線程中創建了一個 Looper對象 可以在子線程里使用消息機制 IntentService 帶了HandlerThread 并且創建了一個子線程的handler 在服務中 創建子線程執行耗時操作 耗時操作執行結束之后服務退出 如果想在Serv…

Hadoop 2.0集群配置詳細教程

Hadoop 2.0集群配置詳細教程 前言 Hadoop2.0介紹 Hadoop是 apache 的開源 項目&#xff0c;開發的主要目的是為了構建可靠&#xff0c;可拓展 scalable &#xff0c;分布式的系 統&#xff0c; hadoop 是一系列的子工程的 總和&#xff0c;其中包含 1. hadoop common &#xff…

php如何減緩gc_管理信息傳播-使用數據科學減緩錯誤信息的傳播

php如何減緩gcWith more people now than ever relying on social media to stay updated on current events, there is an ethical responsibility for hosting companies to defend against false information. Disinformation, which is a type of misinformation that is i…