defaulttokenvaildexceptionhandler.java.svn-base

来自「EasyJWeb是基于java技术」· SVN-BASE 代码 · 共 60 行

SVN-BASE
60
字号
package com.easyjf.web.exception;

import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Method;

import com.easyjf.web.ActionContext;
import com.easyjf.web.WebInvocationParam;
import com.easyjf.web.interceptor.ExceptionInterceptor;

public class DefaultTokenVaildExceptionHandler implements ExceptionInterceptor {

	private String msg = "请求正在处理或已经处理,请不要重复提交";

	public final String getMsg() {
		return msg;
	}

	public final void setMsg(String msg) {
		this.msg = msg;
	}

	public boolean handle(Throwable e, Object target, Method method,
			Object[] args) {
		if (TokenVaildException.class.isAssignableFrom(e.getClass())) {
			if (args.length == 1) {
				WebInvocationParam param = (WebInvocationParam) args[0];
				param.getForm().addResult("msg", msg);
				showInfo();
			}
			return true;
		}
		return false;
	}

	public void showInfo() {
		StringBuilder sb = new StringBuilder();
		sb.append(msg);
		sb.append("<a href='javascript:history.go(-1);'>");
		sb.append("返回");
		sb.append("</a>");
		try {
			ActionContext.getContext().getResponse()
					.setContentType("text/html");
			ActionContext.getContext().getResponse().setCharacterEncoding(
					"UTF-8");
			Writer w = ActionContext.getContext().getResponse().getWriter();
			w.write(sb.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				ActionContext.getContext().getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?