mirror of
https://gitee.com/nutz/nutzboot.git
synced 2024-11-29 18:28:01 +08:00
commit
fd44485fce
@ -0,0 +1,25 @@
|
||||
package io.nutz.demo.simple.handler;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.ErrorHandler;
|
||||
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@IocBean
|
||||
public class MyHandler extends ErrorPageErrorHandler {
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
if(response.getStatus() == 404){
|
||||
response.getWriter().write(Json.toJson(new NutMap("code","-1").setv("msg","404 error")));
|
||||
return;
|
||||
}
|
||||
super.handle(target, baseRequest, request, response);
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.handler.ErrorHandler;
|
||||
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceCollection;
|
||||
@ -194,8 +195,12 @@ public class JettyStarter extends AbstractServletContainerStarter implements Ser
|
||||
wac.getServletContext().setExtendedListenerTypes(true);
|
||||
wac.getSessionHandler().setMaxInactiveInterval(getSessionTimeout());
|
||||
|
||||
ErrorPageErrorHandler ep = new ErrorPageErrorHandler();
|
||||
ep.setErrorPages(getErrorPages());
|
||||
ErrorHandler ep = Lang.first(appContext.getBeans(ErrorHandler.class));
|
||||
if(ep == null){
|
||||
ErrorPageErrorHandler handler = new ErrorPageErrorHandler();
|
||||
handler.setErrorPages(getErrorPages());
|
||||
ep = handler;
|
||||
}
|
||||
wac.setErrorHandler(ep);
|
||||
|
||||
// 设置一下额外的东西
|
||||
|
Loading…
Reference in New Issue
Block a user