zoukankan      html  css  js  c++  java
  • servlet

    @WebServlet("/cdiservlet")      
    public class NewServlet extends HttpServlet {
        private Message message;
    
        @Override             ||重写doGet方法
        public void init() {
            message = new MessageB();    ||对message初始化
        }
    
        @Override
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                      throws IOException {              ||抛出可能出现IO异常
            response.getWriter().write(message.get());   ||捕获可能发生的异常
        }
    }

    public interface Message {         ||servlet实现Message接口的一个对象实例
        public String get();
    }
    public class MessageB implements Message {          ||servlet创建以下对象的实例
        public MessageB() { }
    
        @Override
        public String get() {
            return "message B";
        }
    }
    @WebServlet("/cdiservlet")              ||使用CDI,servlet声明它对Message实例的依赖性,并让它由CDI运行时自动注入
    public class NewServlet extends HttpServlet {
        @Inject private Message message;
    
        @Override
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                      throws IOException {       ||抛出可能出现IO异常
              response.getWriter().write(message.get());  ||捕获可能发生的异常
    }
    }
     
  • 相关阅读:
    phonegap(cordova)环境配置
    Mobile Web调试工具Weinre (reproduce)
    webstorm快捷键
    学习笔记:乘性操作符之求模
    消息队列原理笔记
    运维wiki
    supervisor 文档
    redis 批量删除 keys
    linux命令和工具
    urllib urllib2学习笔记
  • 原文地址:https://www.cnblogs.com/oner-xd/p/10627219.html
Copyright © 2011-2022 走看看