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