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


相关推荐

发表回复

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

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