SCWCD(310-083)

单选题Given the definition of MyServlet: 11.public class MyServlet extends HttpServlet { 12.public void service(HttpServletRequest request, 13.HttpServletResponse response) 14.throws ServletException, IOException { 15.HttpSession session = request.getSession

题目
单选题
Given the definition of MyServlet: 11.public class MyServlet extends HttpServlet { 12.public void service(HttpServletRequest request, 13.HttpServletResponse response) 14.throws ServletException, IOException { 15.HttpSession session = request.getSession(); 16.session.setAttribute("myAttribute","myAttributeValue"); 17.session.invalidate(); 18.response.getWriter().println("value=" + 19.session.getAttribute("myAttribute")); 20.} 21.} What is the result when a request is sent to MyServlet?()
A

An IllegalStateException is thrown at runtime.

B

An InvalidSessionException is thrown at runtime.

C

The string value=null appears in the response stream.

D

The string value=myAttributeValue appears in the response stream.

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

Servlet的基本架构

public class ServletName extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

}

}

1、用String的方法将数据类型转换为String。


正确答案:

 

1、String.valueOf(1.23)

第2题:

在J2EE中,有如下代码在Servlet1.Java中    Import javax.servlet.*;    Import javax.servlet.http.*    Import java.io.IOException;     Import java.io.PrintWriter;    Public class Servlet1 extends HttpServlet{  Public void init () throw ServletException {}   Public void service(HttpServletRequest request,  HttpServletResponce response) throws ServletException,IOException{  PrintWriter out=response.getWriter();   Out.println(“hello!”); } }  假如编译Servlet要具备的环境都已经建立好。现在用完全正确的命令编译该文件,对于以下成熟正确的是()  

  • A、编译该晚间时会提示缺少doGe()t或者doPost(),编译不能够成功通过
  • B、编译后,把Serlvet.cass放在正确的位置,在浏览器中查看该Servlet1,会看到输出文在:“hello!”
  • C、编译后,把Servlet.class放在正确的位置,在浏览器中查看该Servlet1,却看不到任何输出的文字
  • D、编译后,把Servlet.class放在正确的位置,在浏览器中查看该Servlet1,却看到产生运行时错误的出错信息

正确答案:B

第3题:

给定某servlet 程序的片段,如下:

Public void doGet(HttpServletRequest

request,Httpservletresponse response)

{

_________

}

要把session的失效时间设为30分钟,应该在下划线处插入( )

A、request.getSession().setTimeout(1800);

B、request.getSession().setTimeout(30)

C、request.getSession().setMaxInactiveInterval(1800);

D、request.getSession().setMaxInactiveInterval(30);


正确答案:C

第4题:

Given the definition of MyServlet: 11.public class MyServlet extends HttpServlet { 12.public void service(HttpServletRequest request, 13.HttpServletResponse response) 14.throws ServletException, IOException { 15.HttpSession session = request.getSession(); 16.session.setAttribute("myAttribute","myAttributeValue"); 17.session.invalidate(); 18.response.getWriter().println("value=" + 19.session.getAttribute("myAttribute")); 20.} 21.} What is the result when a request is sent to MyServlet?()

  • A、An IllegalStateException is thrown at runtime.
  • B、An InvalidSessionException is thrown at runtime.
  • C、The string "value=null" appears in the response stream.
  • D、The string "value=myAttributeValue" appears in the response stream.

正确答案:A

第5题:

在J2EE中,Servlet1的代码如下:  import javax.servlet.*;  import javax.servlet.http.*; import java.io.*;  public class Servlet1 extends HttpServlet {  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {      response.setContentType("text/html");      PrintWriter out = response.getWriter();      String aa=request.getQueryString();      String bb=request.getMethod();      out.println(aa);  out.println(bb);   } }  把Servlet1.class文件放在Web服务器适合的目录下,在浏览B器地址栏内输入:http://localhost:8080/servlet/Servlet1?name=jb-aptech&phone=12345678,看到的结果是()。 

  • A、name=jb-aptech&phone=12345678 GET
  • B、name=jb-aptech,phone=12345678 GET
  • C、jb-aptech,12345678 POST
  • D、name,phone GET
  • E、2,POST

正确答案:A

第6题:

下面哪个方法不是HttpServlet类:()

  • A、protected void doGet(HttpServletRequest reg,HttpServletResponse res) throws Servlet Exception ,java.io.IOException
  • B、protected void doPost(HttpServletRequest reg,HttpServletResponse res) throws Servlet Exception,java.io.IOException
  • C、protected void doHead(HttpServletRequest reg,HttpServletResponse res) throws Servlet Exception,java.io.IOException
  • D、protected void doReceive(HttpServletRequest reg,HttpServletResponse res) throws ServletException,java.io.IOException

正确答案:D

第7题:

在J2EE中,有如下代码在Servlet1.java中。  import javax.servlet.*;  import javax.servlet.http.*;  import java.io.IOException;  import java.io.PrintWriter;  public class Servlet1 extends HttpServlet {    public void init()  throws ServletException {   }  public void service(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException {      PrintWriter out = response.getWriter();      out.println("hello!");   } }   假如编译Servlet要具备的环境都已经建立好。现在用完全正确的命令编译该文件,对于以下陈述正确的是()。 

  • A、编译该文件时会提示缺少doGet()或者doPost()方法,编译不能够成功通过
  • B、编译后,把Servlet1.class放在正确位置,在浏览器中查看该Servlet1,会看到输出文字:“hello!”
  • C、编译后,把Servlet1.class放在正确位置,在浏览器中查看该Servlet1,却看不到任何输出的文字
  • D、编译后,把Servlet1.class放在正确位置,在浏览器中查看该Servlet1,却看到产生运行时错误的出错信息

正确答案:B

第8题:

GivenanHttpServletRequestrequestandanHttpServletResponseresponse:41.HttpSessionsession=null;42.//insertcodehere43.if(session==null){44.//dosomethingifsessiondoesnotexist45.}else{46.//dosomethingifsessionexists47.}Toimplementthedesignintent,whichstatementmustbeinsertedatline42?()

A.session=response.getSession();

B.session=request.getSession();

C.session=request.getSession(true);

D.session=request.getSession(false);

E.session=request.getSession("jsessionid");


参考答案:D

第9题:

Given an HttpServletRequest request and an HttpServletResponse response: 41.HttpSession session = null; 42.// insert code here 43.if(session == null) { 44.// do something if session does not exist 45.} else { 46.// do something if session exists47. } To implement the design intent,which statement must be inserted at line 42?()

  • A、session = response.getSession();
  • B、session = request.getSession();
  • C、session = request.getSession(true);
  • D、session = request.getSession(false);
  • E、session = request.getSession("jsessionid");

正确答案:D

第10题:

Given an HttpServletRequest request: 22.String id = request.getParameter("jsessionid"); 23.// insert code here 24.String name = (String) session.getAttribute("name"); Which three can be placed at line 23 to retrieve anexisting HttpSession object?()

  • A、HttpSession session = request.getSession();
  • B、HttpSession session = request.getSession(id);
  • C、HttpSession session = request.getSession(true);
  • D、HttpSession session = request.getSession(false);
  • E、HttpSession session = request.getSession("jsessionid");

正确答案:A,C,D

更多相关问题