SSH框架中如何輸出訪問的Action路徑和頁面
阿新 • • 發佈:2019-01-02
public class SystemOutPrint implements Interceptor { public void destroy() { // TODO Auto-generated method stub } public void init() { // TODO Auto-generated method stub } public String intercept(ActionInvocation invocation) throws Exception { Date d1 = new Date();// 計時開始 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String a1 = dateFormat.format(d1); System.out.println("【請求開始】" + a1); System.out.print("Action:" + invocation.getAction().getClass().getName()); HttpServletRequest request = ServletActionContext.getRequest(); String currentURL = request.getRequestURI(); String[] split = currentURL.split("/"); System.out.println("." + split[split.length - 1]); Map<String, Object> parameters = invocation.getInvocationContext().getParameters(); // 輸出傳參 for (String key : parameters.keySet()) { String[] params = (String[]) parameters.get(key); StringBuffer buffer = new StringBuffer(); for (String param : params) { buffer.append("," + param); } String paramValue = buffer.toString(); paramValue = paramValue.substring(1); System.out.println(key + "," + paramValue); } final String resultCode = invocation.invoke();// 攔截器分界 // 輸出頁面 Result realResult = invocation.getResult(); if (realResult instanceof ServletDispatcherResult) { ServletDispatcherResult result = (ServletDispatcherResult) realResult; System.out.println("jsp:" + result.getLastFinalLocation()); } Date d2 = new Date();// 計時結束 System.out.println("【本次操作耗時 " + (d2.getTime() - d1.getTime()) + " 毫秒】");// 輸出耗時 return resultCode; } }