Servlet的基本架构public class ServletName extends HttpServlet {public void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {}public void doGet(HttpServletRequest request, HttpServletResponse response) throws

题目

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。


相似考题
更多“Servlet的基本架构public class ServletName extends HttpServlet {public void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {}public void doGet(HttpServletRequest request, HttpServletResponse response) throws”相关问题
  • 第1题:

    下列哪个选项不是InputStream类中的方法? ( )

    A.public abstract int read()throws IOException

    B.public final void writeInt(int v)throws IOException

    C.public void close()throws IOException

    D.public int available()throws IOException


    正确答案:B

  • 第2题:

    下面哪个方法不是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

  • 第3题:

    在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

  • 第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题:

    Your IT department is building a lightweight Front Controller servlet that invokes an application logic objectwith the interface: public interface ApplicationController {public String invoke(HttpServletRequest request)} The return value of this method indicates a symbolic name of the next view. From this name, the FrontController servlet looks up the JSP URL in a configuration table. This URL might be an absolute path or apath relative to the current request. Next, the Front Controller servlet must send the request to this JSP togenerate the view. Assume that the servlet variable request is assigned the current HttpServletRequestobject and the variable context is assigned the webapp’s ServletContext. Which code snippet of the FrontController servlet accomplishes this goal?()

    • A、Dispatcher view=context.getDispatcher(viewURL);view.forward Request(request, response);
    • B、Dispatcher view=request.getDispatcher(viewURL);view.forward Request(request, response);
    • C、RequestDispatcher view. =context.getRequestDispatcher(viewURL);view.forward(request,response);
    • D、RequestDispatcher view=request.getRequestDispatcher(viewURL);view.forward(request, response);

    正确答案:D

  • 第6题:

    在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 = reponse.getWriter(); Out.println("hello!"); } }  假如要编  译的环境已都已经搭建好。现在用完全正确的命令编译该文件,对于以下陈述正确的是(); 

    • A、编译文件时会提醒缺少doGet和doPost方法,编译不能成功通过
    • B、编译后,把Servlet.Class放在正确的位置,在浏览器查看该Servlet会看到输出文字:“hello”
    • C、编译后,把Servlet.Class放在正确的位置,在浏览器查看该Servlet却看不到任何文字
    • D、编译后,把Servlet.Class放在正确的位置,在浏览器查看该Servlet会却看到运行时的错误信息

    正确答案:B

  • 第7题:

    Given a Filter class definition with this method: 21.public void doFilter(ServletRequest request, 22.ServletResponse response, 23.FilterChain chain) 24.throws ServletException, IOException { 25.// insert code here26. } Which should you insert at line 25 to properly invoke the next filter in the chain,or the target servlet if thereare no more filters?()

    • A、chain.forward(request, response);
    • B、chain.doFilter(request, response);
    • C、request.forward(request, response);
    • D、request.doFilter(request, response);

    正确答案:B

  • 第8题:

    现有:  interface Data {public void load();}  abstract class Info {public abstract void load();}      下列类定义中正确使用Data和Info的是哪项?() 

    • A、 public class Employee implements Info extends Data { public void load(){/*dosomething*/}     }
    • B、public class Employee extends Inf.implements Data{ public void load() {/*do something*/}     }
    • C、public class Empl.yee implements Inf extends Data{ public void Data.1oad(){* do something*/}     public void load(){/*do something*/}     }
    • D、public class Employee extends Inf implements Data  {  public void Data.1oad()  {/*do something*/)     public void info.1oad(){/*do something*/}    }

    正确答案:B

  • 第9题:

    public class TestA{   public void methodA()  throws IOException{   //……   }   }   public class TestB extends TestA{   public void methodA()  throws EOFException{   //……   }   }   public class TestC extends TestA{   public void methodA()  throws Exception{   //……   }   }   当编译类TestC的时候,结果是哪项?() 

    • A、 正常
    • B、 编译错误
    • C、 运行错误
    • D、 以上都不对

    正确答案:B

  • 第10题:

    单选题
    在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,却看到产生运行时错误的出错信息


    正确答案: A
    解析: 暂无解析

  • 第11题:

    单选题
    现有:  interface Data {public void load();}  abstract class Info {public abstract void load();}      下列类定义中正确使用Data和Info的是哪项?()
    A

     public class Employee implements Info extends Data { public void load(){/*dosomething*/}     }

    B

    public class Employee extends Inf.implements Data{ public void load() {/*do something*/}     }

    C

    public class Empl.yee implements Inf extends Data{ public void Data.1oad(){* do something*/}     public void load(){/*do something*/}     }

    D

    public class Employee extends Inf implements Data  {  public void Data.1oad()  {/*do something*/)     public void info.1oad(){/*do something*/}    }


    正确答案: A
    解析: 暂无解析

  • 第12题:

    单选题
    Given: 11.public class MyServlet extends HttpServlet { 12.public void service(HttpServletRequest request, 13.HttpServletResponse response) 14.throws ServletException, IOException { 15.// insert code here 16.} 17.} and this element in the web application’s deployment descriptor: 302 /html/error.html Which,inserted at line 15,causes the container to redirect control to the error.html resource?()
    A

    response.setError(302);

    B

    response.sendError(302);

    C

    response.setStatus(302);

    D

    response.sendRedirect(302);

    E

    response.sendErrorRedirect(302);


    正确答案: A
    解析: 暂无解析

  • 第13题:

    public class SomeException {  } Class a:  public class a {  public void doSomething() { }  } Class b:  public class b extends a {  public void doSomething() throws SomeException { }  }  Which is true about the two classes?() 

    • A、 Compilation of both classes will fail.
    • B、 Compilation of both classes will succeed.
    • C、 Compilation of class a will fail. Compilation of class b will succeed.
    • D、 Compilation of class a will fail. Compilation of class a will succeed.

    正确答案:D

  • 第14题:

    在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

  • 第15题:

    在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

  • 第16题:

    interface Data { public void load(); }  abstract class Info { public abstract void load(); }  Which class correctly uses the Data interface and Info class?() 

    • A、 public class Employee extends Info implements Data { public void load() { /*do something*/ } }
    • B、 public class Employee implements Info extends Data { public void load() { /*do something*/ } }
    • C、 public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }
    • D、 public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }
    • E、 public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }
    • F、 public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }

    正确答案:A

  • 第17题:

    在j2ee中,有如下代码在servlet1.java中  Important javax.servelt.*;  Important javax.servlet.http.*  Import java.io.ioexception  Import java.io.printwriter  Public class servlet1 extends httpservlet{  Public void init() throws serveltexception{ }  Public void service(httpservelt request request,httpserbletresponse response)throws servletexception,ioexception{   Printwriter out=response.getwriter();   Out.println(“hello”); } }  假如编译serblet 要具备的环境都已经建立好,现在用完全正确的命令编译该文件,对于以下陈述正确的是() 

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

    正确答案:B

  • 第18题:

    Given: 11.public class MyServlet extends HttpServlet { 12.public void service(HttpServletRequest request, 13.HttpServletResponse response) 14.throws ServletException, IOException { 15.// insert code here 16.} 17.} and this element in the web application’s deployment descriptor: 302 /html/error.html Which,inserted at line 15,causes the container to redirect control to the error.html resource?()

    • A、response.setError(302);
    • B、response.sendError(302);
    • C、response.setStatus(302);
    • D、response.sendRedirect(302);
    • E、response.sendErrorRedirect(302);

    正确答案:B

  • 第19题:

    Given an HttpServletRequest request and HttpServletResponse response,which sets a cookie "username"with the value "joe" in a servlet?()

    • A、request.addCookie("username", "joe")
    • B、request.setCookie("username", "joe")
    • C、response.addCookie("username", "joe")
    • D、request.addHeader(new Cookie("username", "joe"))
    • E、request.addCookie(new Cookie("username", "joe"))
    • F、response.addCookie(new Cookie("username", "joe"))

    正确答案:F

  • 第20题:

    Given: 3.class MyServlet extends HttpServlet { 4.public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException { 5.// servlet code here ... 26.} 27.} If the DD contains a single security constraint associated with MyServlet and its only  tagsand  tags are:GETPUT Admin Which four requests would be allowed by the container?()

    • A、A user whose role is Admin can perform a PUT.
    • B、A user whose role is Admin can perform a GET.
    • C、A user whose role is Admin can perform a POST.
    • D、A user whose role is Member can perform a PUT.
    • E、A user whose role is Member can perform a POST.
    • F、A user whose role is Member can perform a GET.

    正确答案:A,B,C,E

  • 第21题:

    单选题
    public class TestA{   public void methodA()  throws IOException{   //……   }   }   public class TestB extends TestA{   public void methodA()  throws EOFException{   //……   }   }   public class TestC extends TestA{   public void methodA()  throws Exception{   //……   }   }   当编译类TestC的时候,结果是哪项?()
    A

     正常

    B

     编译错误

    C

     运行错误

    D

     以上都不对


    正确答案: B
    解析: 暂无解析

  • 第22题:

    单选题
    interface Data { public void load(); }  abstract class Info { public abstract void load(); }  Which class correctly uses the Data interface and Info class?()
    A

     public class Employee extends Info implements Data { public void load() { /*do something*/ } }

    B

     public class Employee implements Info extends Data { public void load() { /*do something*/ } }

    C

     public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }

    D

     public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }

    E

     public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }

    F

     public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }


    正确答案: B
    解析: 暂无解析

  • 第23题:

    单选题
    Given a Filter class definition with this method: 21.public void doFilter(ServletRequest request, 22.ServletResponse response, 23.FilterChain chain) 24.throws ServletException, IOException { 25.// insert code here 26.} Which should you insert at line 25 to properly invoke the next filter in the chain, or the target servlet if thereare no more filters?()
    A

    chain.forward(request, response);

    B

    chain.doFilter(request, response);

    C

    request.forward(request, response);

    D

    request.doFilter(request, response);


    正确答案: A
    解析: 暂无解析