Sun River
          Topics about Java SE, Servlet/JSP, JDBC, MultiThread, UML, Design Pattern, CSS, JavaScript, Maven, JBoss, Tomcat, ...
          posts - 78,comments - 0,trackbacks - 0

          Question 1:

          You need to create a database connection in your application after reading the username, password, and database server URL from the deployment descriptor. Which will be the best place to do this?

          Choices:

          • A. Servlet constructor
          • B. init() method
          • C. service() method
          • D. doGet() method
          • E. doPost() method

          Correct choice:

          • B

          Explanation:

          The init() method is invoked once and only once by the container, so the creation of the database connection will be done only once, which is appropriate. The service() , doGet() , and doPost() methods might be called many times by the container.

          The username, password, and URL are to be read from the deployment descriptor. These initialization parameters are contained in the ServletConfig object, which is passed to the init() method. That is why we need to use the init() method instead of the constructor for this purpose, even though the constructor is also called only once.

          Question 2:

          A user can select multiple locations from a list box on an HTML form. Which of the following methods can be used to retrieve all the selected locations?

          Choices:

          • A. getParameter()
          • B. getParameters()
          • C. getParameterValues()
          • D. getParamValues()
          • E. None of the above

          Correct choice:

          • C

          Explanation:

          The getParameterValues(String paraName) method of the ServletRequest interface returns all the values associated with a parameter. It returns an array of Strings containing the values. The getParameter() method returns just one of the values associated with the given parameter, so choice A is incorrect. There are no methods named getParameters() or getParamValues() , so choices B and D are incorrect.

          posted on 2006-10-08 05:01 Sun River 閱讀(283) 評論(0)  編輯  收藏 所屬分類: Servlet & Jsp
          主站蜘蛛池模板: 荃湾区| 清水河县| 克什克腾旗| 乐清市| 札达县| 弥勒县| 达州市| 惠州市| 石屏县| 丁青县| 莫力| 保德县| 南平市| 海安县| 旅游| 武威市| 凭祥市| 永德县| 阿坝县| 民乐县| 通山县| 锡林浩特市| 绍兴县| 湟源县| 张家川| 来宾市| 灵石县| 当阳市| 彩票| 荔浦县| 乌兰浩特市| 攀枝花市| 闵行区| 新乐市| 当涂县| 平和县| 宁都县| 宜宾县| 东乡族自治县| 新巴尔虎左旗| 康定县|