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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • spring boot redis 缓存_redis本地缓存

    spring boot redis 缓存_redis本地缓存SpringBoot集成Redis缓存查询操作是应用中最常见的操作,如果每次查询都从MySQL中查询则会影响效率,通常需要引入缓存来实现查询性能的优化。缓存可以选择本地缓存,远程缓存或本地缓存结合远程缓存。本地缓存可以使用Guava或Caffeine提供的解决方案,而远程缓存则可以选择Redis这样的内存数据库。本文记录一下SpringBoot集成Redis做缓存的相关配置。1引入依赖引入相应Starter。<dependency><gr

    2022年9月17日
  • HTML img图片加载失败时用默认图片替换

    HTML img图片加载失败时用默认图片替换原文地址:http://blog.csdn.net/qq_24771775/article/details/50294931 img元素加载图片失败,则变成一个小图标,让页面变得难看。此时如何替换为默认图片?onerror属性img元素自带onerror属性,加载失败时,触发error事件src=”http://yongqing.is-programmer.com/posts/i

    2022年6月1日
  • Python—海龟作图

    Python—海龟作图1、因为海龟作图需要用到”turtle”库,所以先介绍库的三种引用方法:(1):from库名import函数名/*;(2):import库名——>使用时:库名.函数名(3):import库名as函数名2、turtle的使用方法:(1)Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行的路径上绘制了图形。(2)画布:就是海

    2022年6月28日
  • 关于adventure的短语_adventureinwellies

    关于adventure的短语_adventureinwelliesdown了个AdventureWorks2008的数据库备份,没办法谁让一些书上用这个库作为示例呢。主要差别是Person表格,搞不清楚为什么MS在搞什么。用MS提供的安装文件,就是装不上。还有很多人提到那个FileStream的设置,可是根本没用。

    2022年9月12日
  • Laravel 底层原理:门面(Facades)

    Laravel 底层原理:门面(Facades)

    2022年2月15日
  • C++有序双向链表

    C++有序双向链表

    2021年8月20日

发表回复

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

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