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


相关推荐

  • android 之旋转罗盘 风车 开发[通俗易懂]

    android 之旋转罗盘 风车 开发[通俗易懂]我要介绍的是一个能旋转的view,说这个view能旋转有点不切实际,那是视觉效果,其实是对图片的旋转。目前它只支持图片。你可以把它认为是一个能响应手势旋转的View。它的功能有:1.会响应手势旋转2

    2022年8月3日
    11
  • cada0图纸尺寸_a0图纸尺寸[通俗易懂]

    cada0图纸尺寸_a0图纸尺寸[通俗易懂]a0图纸尺寸a0图纸尺寸问题:a0图纸尺寸答案:841mm*1189mm【相关阅读】1、什么是a0图纸a0图纸是一种很大的绘图纸,这种纸张比一般的复印纸要厚,也比一般的复印纸要黄一点,这种绘图纸一面比较光滑,适合画图用,另一面比较粗糙。但是很多人都感觉不出来,也看不出来。a0图纸广泛的运用于各种建筑设计,规划设计,工业设计,产品设计等等,很多这个专业的学生,从大一开…

    2022年6月20日
    74
  • Python如何将py文件打包成exe[通俗易懂]

    Python如何将py文件打包成exe[通俗易懂]安装pyinstaller打开cmd窗口,输入pipinstallpyinstaller,命令行输出successfully表示成功。生成exe文件一、单个py文件在py文件目录下,打开c

    2022年7月6日
    39
  • goc课程介绍_演示

    goc课程介绍_演示第一课GoC简介和演示【C/C++程序设计语言】“程序设计语言用于书写计算机程序的语言。语言的基础是一组记号和一组规则。根据规则由记号构成的记号串的总体就是语言。在程序设计语言中,这些记号串就是程序。”(这是百度百科上的程序设计语言定义)通俗的讲,程序是由一些“命令”组成,这些“命令”是一些符合指定规则的符号。根据不同的需求和规则,现今有近百种有不同的编程语言,C/C++是最流…

    2022年4月19日
    76
  • linux两个文件修改主机名

    linux修改主机名的方法用hostname命令可以临时修改机器名,但机器重新启动之后就会恢复原来的值。#hostname//查看机器名#hostname-i//查看本机器名对应的ip地址

    2021年12月24日
    39
  • 淘宝、天猫、京东、苏宁等平台抢购脚本

    淘宝、天猫、京东、苏宁等平台抢购脚本淘宝、天猫、京东、苏宁等平台抢购脚本扫码添加“SevenBlog”公众号,获取更多好玩脚本进入正题:建议使用Chrome浏览器1、安装浏览器插件,Ghelper(需要注册账号)打开浏览器扩展程序,并且打开开发者模式,将下载好的Ghelper解压,然后添加已解压的扩展程序2、浏览器地址栏输入chrome://apps/,并打开下面的网上应用店…

    2022年6月7日
    54

发表回复

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

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