二、Servlet 的注解及容器初始化 [不推荐]
Solon 对应的相关处理,可见:《过滤器、路由拦截器、处理器、拦截器》
1、支持 Servlet 注解
- WebServlet
@WebServlet("/heihei/*")
public class HeheServlet extends HttpServlet {
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
res.getWriter().write("OK");
}
}
- WebFilter
@WebFilter("/demo/*")
public class DemoFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException {
res.getWriter().write("Hello,我把你过滤了");
}
}
2、支持 ServletContainerInitializer 配置
@Configuration
public class DemoConfiguration implements ServletContainerInitializer{
@Override
public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
//...
}
}