第九章测试
1.使得HttpSession失效的三种方式是:关闭浏览器、调用session的invalidate方法和等待session超时。
A:错 B:对
答案:B
2.ServletContext的说法合法的是______________________。
A: 一个应用对应一个ServletContext B:第一个会话在ServletContext中保存了数据,第二个会话读取不到这些数据 C:ServletContext使用setAttribute()和getAttribute()方法操作数据 D:ServletContext的范围比Session的范围要大 3.下列选项中可以关闭会话的是__________________。
A:等待HttpSession超时 B:调用HttpSession的close()方法 C:调用HttpSession的invalidate()方法 D:调用HttpServletRequest的getSession(false)方法 4.Servlet中会话跟踪技术的方案有Cookie、Session、URL重写和隐藏表单域技术。
A:对 B:错 5.HttpServletRequest的______方法可以得到会话。
A:getRequestSession() B:getSession() C:getSession(true) D:getHttpSession() 6.通过ServletConfig对象的getInitParameter()方法可以获取Servlet初始化参数。
A:对 B:错 7.ServletContext对象除了获取初始化参数外,还可以存储数据。但ServletConfig对象只能获取初始化参数,不能用来存储数据。
A:错 B:对 8.写入和读取Cookie的代码分别是(  )。
A:request.addCookies()和response.getCookies()  B:response.addCookie()和request.getCookie() C:response.addCookies()和request.getCookies() D:response.addCookie()和request.getCookies() 9.关于会话超时,以下()是正确的?
A:在web.xml文件中会话超时声明是以秒为单位的  B:在web.xml文件中会话超时声明是以分钟为单位的 C:通过程序中的方法setMaxInactiveInterval( int interval)设置会话超时是以分钟为单位的 D:通过程序中的方法setMaxInactiveInterval( int interval)设置会话超时是以秒为单位的 10.HTTP是一个()的协议。
A:无状态 B:状态良好 C:有状态 D:局域网 11.下面()是应用程序上下文。
A:HttpServletResponse B:HttpSession C:HttpServletRequest D:ServletContext 12.不同的客户端需要共享的信息应存储到()中。
A:Http响应对象 B:Http请求对象 C:应用程序上下文  D:会话对象 13. JSP中有如下代码:<%    Cookie c = new Cookie("name" , "admin");    c.setMaxAge(10000);    response.addCookie(c);%>()可以正确显示"admin" ? 
A:${cookie.name}  B:${ name} C:${cookie.name.value}  D:${name.value} 14.在J2EE中,在web.xml中,有如下代码:<session - config>         <session - timeout>30</session - timeout></session - config>上述代码定义了默认的会话超时时长,时长为30( ) 。
A:小时 B:分钟 C:秒 D:毫秒   15.属于HttpSession对象的方法有哪些?
A:String getId(); B:boolean  isNew(); C:Object getAttribute(String attributeName); D:void setMaxInactiveInterval(); 16.属于Cookie对象的方法有()。
A:Cookie []cookies=request.getCookies(); B:cookie.setMaxAge(60*60*24*7); C:Cookie cookie=new Cookie(userID,"admin123"); D:response.addCookie(cookie); 17.Cookie常用方法的说明正确的有哪些?
A:通过getValue()方法可以获取Cookie对象的值 B:调用request.getCookies()可以得到Cookie对象组成的数组 C:setMaxAge()用来设置Cookie的有效时间,以秒为单位。 D:通过getName()方法可以获取Cookie对象的名称

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