1+1+1(JSP补考测试题
(理论考试60分钟)
一、单选题(每题2分,共30分)下列各题A、B、C、D四个选项中,只有一个选项是正确的,请将正确选项的标记写在题干后的括号内。
1、给定一个Servlet 的doGet方法中的代码片段,如下:
request.setAttribute(“name”,”zhang”);
response.sendRedirect(“http://localhost:8080/servlet/MyServlt”);
那么在MyServlet 中可以使用()方法把属性name的值取出来。(选择一项)( )
A.String str=request.getAttribute(“name”);
B.String str=(String)request.getAttribute(“name”);
C.Object str=request.getAttribute(“name”);
D.无法取出来
2、J2EE 中,()类的()方法用于创建对话。( )
A.HttpServletRequest、getSession
B.HttpServletResponse、newSession
C.HtttpSession、newInstance
D.HttpSession、getSession
3、以下代码能否编译通过,假如能编译通过,运行时得到什么打印结果?()request.setAttribute(\"count\",new Integer(0));
Integer count = request.getAttribute(\"count\");
选项:
A.不能编译通过 B.能编译通过,并正常运行
C.编译通过,但运行时抛出ClassCastExceptio
4、在J2EE中,以下对RequestDispatcher描述正确的是( )。
A.Jsp中有个隐含的对象diapatcher,它的类型是RequestDispatcher
B.ServletConfig有一个方法:getRequestDispatcher可以返回RequestDipatcher对象
C.RequestDipatcher 有一个方法:forward可以把请求继续传递给别的Servlet或者JSP界面
D.JSP中有个隐含的默认对象request,它的类型是RequestDipatcher
5、给定一个Servlet的代码片段如下:
Public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
_______________________
out.println(“hi kitty!”);
out.close();
}
运行次Servlet时输出如下:
hi kitty!