struts2使用AbstractInterceptor拦截器 获取参数以及修改参数的值

struts2使用AbstractInterceptor拦截器 获取参数以及修改参数的值publicclassAppLoginInterceptorextendsAbstractInterceptor{ @Override publicStringintercept(ActionInvocationinvocation)throwsException{ Mapmap=invocation.getInvocationContext().getSes…

大家好,又见面了,我是你们的朋友全栈君。

public class AppLoginInterceptor extends AbstractInterceptor{

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Map map = invocation.getInvocationContext().getSession();
		    
         
    if(!invocation.getInvocationContext().getParameters().containsKey("accountcode"))
			{
				String accountcode=(String)map.get("accountcodeLocal");
				if(accountcode!=null && !accountcode.trim().equals(""))
				{
					invocation.getInvocationContext().getParameters().put("accountcode", accountcode);
				}
			}
			if(!invocation.getInvocationContext().getParameters().containsKey("customercode"))
			{
				String customercode=(String)map.get("customercodeLocal");
				if(customercode!=null && !customercode.trim().equals(""))
				{
					invocation.getInvocationContext().getParameters().put("customercode", customercode);
				}
			}
			
			
			if(invocation.getInvocationContext().getParameters().containsKey("accountcode") && invocation.getInvocationContext().getParameters().containsKey("securityKey")&& invocation.getInvocationContext().getParameters().containsKey("customercode"))
			{
				String[] customer=(String[])invocation.getInvocationContext().getParameters().get("customercode");
				String[] key=(String[])invocation.getInvocationContext().getParameters().get("securityKey");
				String[] code=(String[])invocation.getInvocationContext().getParameters().get("accountcode");
				String customercode = customer[0];
				String accountcode = code[0];
				String securityKey = key[0];
				System.out.println("客戶編號---"+customercode+"--替換編譯前-----accountcode=="+accountcode+"--------securityKey---"+securityKey);
				if(accountcode!=null && !accountcode.trim().equals("") && customercode!=null && !customercode.trim().equals("") && securityKey!=null && !securityKey.trim().equals(""))
				{
					String securityKey2 = new MD5().getMD5ofStr(customercode+accountcode);
					if(securityKey2.equals(securityKey))
					{
						accountcode=accountcode.replaceAll("-sas-", "_");
						invocation.getInvocationContext().getParameters().put("securityKey", new MD5().getMD5ofStr(customercode+accountcode));
						invocation.getInvocationContext().getParameters().put("accountcode", accountcode);
						System.out.println("客戶編號---"+customercode+"--替換編譯後-----accountcode======="+accountcode+"--------securityKey---"+new MD5().getMD5ofStr(customercode+accountcode));
					}
				}
			}	







		return invocation.invoke();
	}
}

具体代码测试一下就知道了 debug 下 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/146402.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • ping命令的使用及代码_通过命令查看ping路径

    ping命令的使用及代码_通过命令查看ping路径在这个时代,科技越来越发达,网络已经越来越成为人们不可缺少的一部分。计算机也已经是很多学校的课程了,因为计算机技术是非常有技术性的专业,它其中涉及到很多专业知识,需要通过学习才能掌握。今日小编就为大家介绍一个计算机的命令,它叫做Ping,这边介绍一下它的入门知识,主要是关于ping连接和命令方面的介绍。  1、Ping的基础知识  ping命令相信大家已经再熟悉不过了,但是能把ping的功能发…

    2022年4月19日
    801
  • SQL语句嵌套最好用quotedstr函数替换

    SQL语句嵌套最好用quotedstr函数替换
    dmcc.delete_rm_zjfhsj.add(‘select数量fromrm_zjfhsjwhere类型=’CTO”);dmcc.delete_rm_zjfhsj.SQL.add(‘select数量fromrm_zjfhsjwhere类型=’+quotedstr(‘CTO’));凡是内引号对,最好用quotedstr函数替换

    2022年10月17日
    5
  • 图片爬虫

    图片爬虫参考视频学习,堆糖网图片爬虫"""1.URL2.模拟浏览器请求资源3.解析网页4.保存数据到本地"""importrequests#第三方库importurllib.parseimportjsonimportjsonpathurl=’https://www.duitang.com/napi/blog/list/by_search/?kw={}&s…

    2022年6月17日
    31
  • mysql grant 使用 授权 添加用户

    mysql grant 使用 授权 添加用户

    2021年4月29日
    147
  • Hadoop 中xsync集群分发脚本

    Hadoop 中xsync集群分发脚本大数据集群中使用xsync脚本分发文件到集群中的所有机器

    2022年5月24日
    43
  • 最全的PHP后台管理系统源码「建议收藏」

    最全的PHP后台管理系统源码「建议收藏」一款PHP语言基于ThinkPhp6.x+Layui+MySQL等框架精心打造的一款模块化、插件化、高性能的前后端分离架构敏捷开发框架,可用于快速搭建前后端分离后台管理系统,本着简化开发、提升开发效率的初衷,框架自研了一套个性化的组件,实现了可插拔的组件式开发方式:单图上传、多图上传、下拉选择、开关按钮、单选按钮、多选按钮、图片裁剪等等一系列个性化、轻量级的组件,是一款真正意义上实现组件化开发的敏捷开发框架,框架已集成了完整的RBAC权限架构和常规基础模块,同时支持多

    2025年12月10日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号