Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. public abstract class CustomServlet extends HttpServlet {
  2.  
  3. private static AtomicBoolean loaded = new AtomicBoolean();
  4.  
  5. @Override
  6. public void init() throws ServletException {
  7. if (!loaded.getAndSet(true)) {
  8. InputStream input = getServletContext().getResourceAsStream("/WEB-INF/custom-config.xml");
  9. // ...
  10. }
  11. }
  12.  
  13. // ...
  14. }
  15.  
  16. @WebListener
  17. public class Config implements ServletContextListener {
  18.  
  19. @Override
  20. public void contextInitialized(ServletContextEvent event) {
  21. InputStream input = event.getServletContext().getResourceAsStream("/WEB-INF/custom-config.xml");
  22. // ...
  23. }
  24.  
  25. // ...
  26. }
  27.  
  28. public abstract class BaseServlet extends HttpServlet{
  29.  
  30. public Base(){
  31. loadXml();
  32. }
  33. private void loadXml(){
  34. ...
  35. }
  36. }
  37.  
  38. public class Servlet1 extends BaseServlet {
  39. ...
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement