第五章单元测试
  1. 在编写Servlet时需要( )。

  2. A:实现HttpRequestServlet B:继承Servlet C:继承HttpServlet D:实现HttpRequest
    答案:继承HttpServlet
  3. Servlet需要在( )文件中进行配置。

  4. A:web.xml B:webapp.xml C:context.xml D:web.config
  5. Servlet 可以在以下哪三个不同的作用域存储数据。( )

  6. A:请求、响应和会话 B:请求、响应和上下文 C:响应、会话和上下文 D:请求、会话和上下文
  7. 给定一个Servlet的doGet方法中的代码片段,如下:
    request.setAttribute(“name”,“zhang”);
    response.sendRedirect(“http://localhost:8080/servlet/MyServlt”);
    那么在 MyServlet中可以使用哪个方法把属性 name的值取出来。( )

  8. A:String str = (String)request.getAttribute(“name”); B:Object str = request.getAttribute(“name”); C:String str = request.getAttribute(“name”); D:无法取出来
  9. 包含Servlet发回到客户端信息的ServletResponse对象是由( )创建的。

  10. A:Servlet对象 B:Web服务器的Servlet容器 C:客户端的浏览器 D:Web服务器的HTTP引擎
  11. 在J2EE中,对于HttpServlet类的描述,错误的是( )。

  12. A:HttpServlet类中处理客户请求和响应时所使用的两个接口是:HttpServletRequest和HttpServletResponse B:我们自己编写的Servlet继承了HttpServlet类,一定需覆盖doPost或者doGet C:HttpServlet类扩展了GenericServlet类,实现了GenericServlet类的抽象方法 D:我们自己编写的servlet继承了Httpservlet类,一般只需要覆盖doPost方法,不必覆盖servive()方法,因为一个service()方法会调用doPost或者doGet方法
  13. 假设在helloapp应用中有一个HelloServlet类,它在web.xml文件中的配置如下:
    <servlet>
    <servlet-name> HelloServlet </servlet-name>
    <servlet-class>org.javathinker.HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/hello</url-pattern>
    </servlet-mapping>
    那么在浏览器端访问HelloServlet的URL是什么? ( )


  14. A:http://localhost:8080/helloapp/org/javathinker/hello B:http://localhost:8080/helloapp/hello C:http://localhost:8080/helloapp/HelloServlet D:http://localhost:8080/HelloServlet
  15. 使用Tomcat,通常会设置环境变量CATALINA_HOME指向安装目录; web应用程序的缺省部署目录在安装目录下的哪个子目录。( )

  16. A:webapps B:JAVA_HOME C:conf D:Lib
  17. 不能在不同用户之间共享数据的方法是( )。

  18. A:通过Cookie B:通过ServletContext对象 C:利用数据库 D:利用文件系统

温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!
点赞(3) dxwkbang
返回
顶部