• 2021-04-14
    在J2EE中,给定某Servlet的代码如下,编译运行该文件,以下陈述正确的是
    PublicclassServlet1extendsHttpServlet{
    Publicvoidinit()throwsServletException{
    }
    Publicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)
    ThrowsServletException,IOException{
    PrintWriterout=response.getWriter();
    out.println(“hello!”);
    }}
  • 编译后,把Servlet1.class放在正确位置,运行该Servlet,在浏览器中会看到输出文字:hello!

    举一反三

    内容

    • 0

      在Servlet中有一段代码如下 public void doPost(HttpServletRequestrequest, HttpServletResponse response) throwsServletException, IOException { request.setAttribute("name", new Integer(100)); response.sendRedirect("show.jsp"); } 在show.jsp中 <%=request.getAttribute("name")%> 页面结果为

    • 1

      在Servlet中有一段代码如下 public void doPost(HttpServletRequestrequest, HttpServletResponse response)throwsServletException, IOException { request.setAttribute("name", new Integer(100)); response.sendRedirect("show.jsp"); } 在show.jsp中 页面结果为( ) A: 100 B: java.lang.Intege C: Intege D:

    • 2

      中国大学MOOC:publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{request.getSession().getAttribute(“A”);//第二行}假定第二行返回的对象引用不是null,那么这个对象存储在()范围中。

    • 3

      给定一个Servlet的代码片段如下: Public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ ______ out.println("hi kitty! "); out.close(); } 运行Servlet时输出:hi kitty! 则应在此Servlet下划线处填充如下代码

    • 4

      阅读下列的代码 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{ out.println("hello kity!"); } 若使Servlet运行的结果为hi kitty!,填写在空白处的代码为() 则应在此Servlet下划线处添加如下()代码