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


相关推荐

  • localdate转date时区问题_Date和LocalDate互转「建议收藏」

    localdate转date时区问题_Date和LocalDate互转「建议收藏」一.简述Date对象表示特定的日期和时间,而LocalDate(Java8)对象只包含没有任何时间信息的日期。因此,如果我们只关心日期而不是时间信息,则可以在Date和LocalDate之间进行转换。二.Date转LocalDate如果要将Java.util.Date转换为java.time.LocalDate,可以使用以下步骤:1)将java.util.Date转换为ZonedDateTime。…

    2022年10月3日
    3
  • Protel 99SE汉化教程

    Protel 99SE汉化教程Protel99se是一款设计电路原理图和PCB的专业软件,它是由ProklTechnology开发出来的电路板设计软件,拥有功能强大、界面简洁等特点。Protel99se软件是由两大部分组成:电路原理图设计(AdvancedSchematic)和多层印刷电路板设计(AdvancedPCB)。安装教程原文链接:https://blog.csdn.net/weixin_42693097/a…

    2022年5月30日
    152
  • 扩频调制matlab仿真

    扩频调制matlab仿真扩频调制1.扩频调制概念2.仿真代码(matlab)2.1主程序2.2产生m序列函数3.实验结果1.扩频调制概念扩展频谱是指将信号的频谱扩展至占用很宽的频带,简称扩频。扩展频谱通信系统是将基带信号的频谱通过某种调制扩展到远大于原基带信号带宽的系统。扩展频谱技术一般可以分为三类:1.直接序列扩谱,它通常用一段伪随机序列表示一个信息码元,对载波进行调制。2.跳频扩谱,它是发射机的载频在一个信…

    2022年5月8日
    54
  • UIControl-IOS开发

    UIControl-IOS开发

    2021年12月7日
    43
  • python interpolate.interp1d_将MATLAB的interp1转换为Python interp1d

    python interpolate.interp1d_将MATLAB的interp1转换为Python interp1d我正在将MATLAB代码转换为Python代码。在代码使用MATLAB中的函数interp1。我发现scipy函数interp1d应该是我想要的,但我不确定。你能告诉我我实现的代码是否正确吗?我的Python版本是3.4.1,MATLAB版本是R2013a,但是代码已经在2010年左右实现了]。在MATLAB:S_T=[0.0,2.181716948,4.363766232,6.5464…

    2022年4月30日
    63
  • dainying

    dainyingmagnet:?xt=urn:btih:DB334CEAFC75A4045D5958159D972B1CCEC1C590

    2022年7月2日
    23

发表回复

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

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