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 閱讀(276) 評論(0)  編輯  收藏 所屬分類: Servlet & Jsp
          主站蜘蛛池模板: 内黄县| 海伦市| 博白县| 哈密市| 枣庄市| 永福县| 盐源县| 武隆县| 常德市| 庄浪县| 桑植县| 定南县| 衢州市| 西宁市| 惠东县| 陈巴尔虎旗| 隆林| 凭祥市| 泰州市| 平武县| 静乐县| 宁津县| 民勤县| 海城市| 浙江省| 民权县| 武城县| 巴东县| 吴川市| 岫岩| 肃南| 杂多县| 格尔木市| 泽州县| 手机| 万宁市| 象山县| 澳门| 永和县| 沾化县| 长泰县|