package cn.test.filter;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import org.nutz.boot.starter.WebFilterFace;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@IocBean
public class WxFilterStarter implements WebFilterFace {
private static final Logger logger = LoggerFactory.getLogger(WxFilterStarter.class);
@Inject("refer:$ioc")
protected Ioc ioc;
@Inject
protected PropertiesProxy conf;
@Override
public String getName() {
return "WxFilter";
}
@Override
public String getPathSpec() {
return "/*";
}
@Override
public EnumSet<DispatcherType> getDispatches() {
return EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE);
}
@IocBean(name = "wxFilter")
public WxFilter createNutFilter() {
return new WxFilter();
}
@Override
public Filter getFilter() {
return ioc.get(WxFilter.class, "wxFilter");
}
@Override
public Map<String, String> getInitParameters() {
return new HashMap<String,String>();
}
@Override
public int getOrder() {
return 60;
}
}
package cn.test.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WxFilter implements Filter {
private static final Logger logger = LoggerFactory.getLogger(WxFilter.class);
// @Inject("refer:$ioc")
// protected Ioc ioc;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
logger.debug("\r\n=======================================filter init...");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
// TODO Auto-generated method stub
logger.debug("\\r\\n=======================================filter doFilter...");
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
String contextPath = req.getContextPath();
System.err.println(contextPath);
chain.doFilter(request, response);
}
@Override
public void destroy() {
logger.debug("\\r\\n=======================================filter destroy...");
}
}
可以出现“==filter init...”,但访问网址时,不调用doFilter()
现在Nutzboot只能直接加Filter吗,有没有Nutz的MVC里自己的Filter链?
请指点下