惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
L
LINUX DO - 最新话题
云风的 BLOG
云风的 BLOG
Know Your Adversary
Know Your Adversary
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
V
V2EX
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
D
DataBreaches.Net
C
Cyber Attacks, Cyber Crime and Cyber Security
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
AWS News Blog
AWS News Blog
Forbes - Security
Forbes - Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
J
Java Code Geeks
美团技术团队
C
Cybersecurity and Infrastructure Security Agency CISA
Project Zero
Project Zero
Recorded Future
Recorded Future
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LINUX DO - 热门话题
W
WeLiveSecurity
V
Visual Studio Blog
Schneier on Security
Schneier on Security
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
aimingoo的专栏
aimingoo的专栏
V2EX - 技术
V2EX - 技术
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
U
Unit 42
N
Netflix TechBlog - Medium
F
Fortinet All Blogs
博客园_首页
I
InfoQ
Spread Privacy
Spread Privacy
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
月光博客
月光博客
I
Intezer
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
Arctic Wolf
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
The Exploit Database - CXSecurity.com
Google DeepMind News
Google DeepMind News

博客园 - 山里人家

PHP魔术函数集锦 gbk gb2312 utf8区别 适合初学者,用MyEclipse编写第一个j2me MyEclipse开发手机程序-安装开发环境(图解) - 山里人家 - 博客园 javascript 常用语法词典 - 山里人家 - 博客园 电脑高手最常用的5个按钮! 汇总Eclipse快捷键 myeclipse7汉化 S2SH配置 - 山里人家 - 博客园 struts2 ognl 与 jsp2.1 el 的冲突问题 STRUTS2 ACTION的跳转类型说明 JXL读取EXCEL STRUTS 2之 标签 myeclipse 快捷键 STRUTS2 ACTION的扩展名修改方法 ASP.NET网络编程中经常用到的27个函数集 Asp.Net细节性问题技巧精萃 DIV确认对话框 JXL包使用
struts2通过拦截器实现用户权限验证
山里人家 · 2008-08-20 · via 博客园 - 山里人家

在需要验证的包上加上配置

<interceptors>
   <!-- 定义了一个名为mylogin的拦截器 -->
   <interceptor name="mylogin" class="Action.LogonInterceptor" />
   <interceptor-stack name="logintest">
    <interceptor-ref name="mylogin" />
    <interceptor-ref name="paramsPrepareParamsStack" />
   </interceptor-stack>
  </interceptors>

  <!-- 默认执行的拦截器 -->
  <default-interceptor-ref name="logintest" />

  <global-results>
   <!-- 当返回login视图名时,转入/login.jsp页面 -->
   <result name="login" type="redirect">/login.jsp</result>
  </global-results>

/**
 *
 */
package Action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * @author hbl//用户登陆权限验证;
 *
 */
public class LogonInterceptor extends AbstractInterceptor  {
  public String intercept(ActionInvocation invocation) throws Exception {  
         // 取得请求相关的ActionContext实例  
         ActionContext ctx=invocation.getInvocationContext();
         if(ctx.getSession().get("userinfo")==null)//未登陆
         {
          // return invocation.invoke();
          return "login";
          
         }
          return invocation.invoke();
     }  


}

第一次使用,只是简单的测试,用户的session,作个标记。