用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
ewsl的公告
本站点都是本人在开发中遇到,解决和想到的问题.基本上都是我的经验总结.希望能在开发的时候帮大家一点忙,少走一点弯路.还有一些是对现有系统的一些不成熟的想法
文章分类
存档

原创  在Struts2 上面写的一个将JSP全部转移到WEB-INF下的拦截器 收藏

 在Struts2 上面写的一个将JSP全部转移到WEB-INF下的拦截器,以下是具体代码和配置
package com.stockvote.interceptor;



import java.util.Map;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class WebInfInterceptor implements Interceptor {
    
private static String PathPrefix = "/WEB-INF/";
    
private static final String LOCATION = "location";
    
    
public void destroy() {

    }


    
public void init() {
        
if (PathPrefix.endsWith("/")) {
            PathPrefix 
= PathPrefix.substring(0, PathPrefix.length() - 1);
        }

    }


    
public String intercept(ActionInvocation arg0) throws Exception {

        Map map 
= arg0.getProxy().getConfig().getResults();

        
for (java.util.Iterator iter = map.values().iterator(); iter.hasNext();) {
            ResultConfig rcg 
= (ResultConfig) iter.next();
            transferLocation(rcg);
        }


        
return arg0.invoke();
    }


    
public void transferLocation(ResultConfig rcg) {

        Map map 
= rcg.getParams();

        
if (!map.containsKey(LOCATION)) {
            
return;
        }


        
// ////////////////////
        String location = (String) map.get(LOCATION);

        
if (location.startsWith(PathPrefix)) {
            
return;
        }


        
if (!location.startsWith("/")) {
            location 
= "/" + location;
        }


        location 
= PathPrefix + location;

        map.put(LOCATION, location);
    }

}

下面是xml配置

<interceptor name="WebInfoPath" class="com.stockvote.interceptor.WebInfointerceptor"></interceptor>
            
            
<interceptor-stack name="defaultStack1">
            
<!--interceptor-ref name="log"></interceptor-ref!-->
            
<interceptor-ref name="defaultStack"></interceptor-ref>
            
<interceptor-ref name="WebInfoPath"></interceptor-ref>
            
            
</interceptor-stack>
            
</interceptors>
            
<default-interceptor-ref name="defaultStack1"></default-interceptor-ref>
        

发表于 @ 2007年10月31日 22:49:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇: 使用 FancyUpload需要注意的一点 | 新一篇:二维稀疏矩阵的简单实现,其他维数的可以参照实现

  • 发表评论
  • 评论内容:
  •  
Copyright © ewsl
Powered by CSDN Blog