public class MyActionHandler extends ActionHandler{
private static final Log log = Log.getLog(MyActionHandler.class);
public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
if (target.indexOf('.') != -1) {
return ;
}
String[] urlPara = {null};
Action action = getAction(target, urlPara);
if (action == null) {
if (log.isWarnEnabled()) {
String qs = request.getQueryString();
log.warn(IpUtils.getIpAddress(request)+" -- 404 Action Not Found: " + (qs == null ? target : target + "?" + qs));
}
renderManager.getRenderFactory().getErrorRender(404).setContext(request, response).render();
return ;
}
super.handle(target, request, response, isHandled);
}
}主要是继承ActionHandler,覆盖掉父类的 handler 方法,加上的 ip 输出:
log.warn(IpUtils.getIpAddress(request)+" -- 404 Action Not Found: " + (qs == null ? target : target + "?" + qs));
在public void configHandler(Handlers me)中添加自定义MyActionHandler
public void configHandler(Handlers me) {
me.setActionHandler(new MyActionHandler());
}