需求是:在错误页面输出当前url
1、创建拦截器
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.ActionException;
public class ErrorPageInterceptor implements Interceptor {
public void intercept(Invocation inv) {
try {
inv.invoke();
} catch (ActionException e) {
inv.getController().setAttr("actionKey", inv.getActionKey());
int errorCode = e.getErrorCode();
if (errorCode == 404 || errorCode == 500) {
inv.getController().render("/_view/common/" + errorCode + ".html");
} else {
inv.getController().render("/_view/common/error.html");
}
}
}
}2、在项目配置xxConfig中添加此拦截器
public void configInterceptor(Interceptors me) {
me.add(new ErrorPageInterceptor());
}3、在错误页面的模板404.html文件中使用#(actionKey)输出当前页面的url
感谢波总提供的思路
顺问还有没有更简洁的实现方法?