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

推荐订阅源

B
Blog
I
InfoQ
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
博客园_首页
The Cloudflare Blog
博客园 - 【当耐特】
Engineering at Meta
Engineering at Meta
罗磊的独立博客
月光博客
月光博客
V
V2EX
大猫的无限游戏
大猫的无限游戏
腾讯CDC
GbyAI
GbyAI
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Attack and Defense Labs
Attack and Defense Labs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
B
Blog RSS Feed
Webroot Blog
Webroot Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
Netflix TechBlog - Medium
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Vercel News
Vercel News
C
CERT Recently Published Vulnerability Notes
人人都是产品经理
人人都是产品经理
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Recent Announcements
Recent Announcements
Cyberwarzone
Cyberwarzone
G
Google Developers Blog
H
Heimdal Security Blog
MyScale Blog
MyScale Blog
The Register - Security
The Register - Security
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
T
Tenable Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
O
OpenAI News
C
Check Point Blog
Forbes - Security
Forbes - Security
SecWiki News
SecWiki News
K
Kaspersky official blog
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Full Disclosure
阮一峰的网络日志
阮一峰的网络日志

博客园 - 山里人家

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,作个标记。