网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
8、给定一个Servlet的代码片段如下: () public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ ______ out.println(“hi kitty!”); out.close(); } 运行此Servlet时输出如下: hi kitty! 则应在此Servlet下划线处填充如下代码。
A.PrintWriter out = response.getWriter();
B.PrintWriter out = request.getWriter();
C.OutputStream out = response.getOutputStream();
D.OutputStream out = request.getWriter();
参考答案和解析
B
更多 “8、给定一个Servlet的代码片段如下: () public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ ______ out.println(“hi kitty!”); out.close(); } 运行此Servlet时输出如下: hi kitty! 则应在此Servlet下划线处填充如下代码。A.PrintWriter out = response.getWriter();B.PrintWriter out = request.getWriter();C.OutputStream out = response.getOutputStream();D.OutputStream out = request.getWriter();” 相关考题
考题
在J2EE中,Servlet1中有如下代码:PrintWriter out=response.getWriter();out.println("请同学们仔细看题目再回答!");假设该Servlet运行的平台是ApacheTomcat4.03以下版本。为了可以在浏览器中显示汉字,可以()。
A.在这两行代码前加上代码:response.setContentType(text/html,charset=GBK);B.已经可以显示汉字,不用添加任何代码C.在这两行代码前加上代码:response.setContentType(text/html);D.在这两行代码前加上代码:response.setContentType(text/html,charset=gb2312);
考题
在J2EE中,Servlet1的代码如下:importjavax.servlet.*;importjavax.servlet.http.*;importjava.io.*;publicclassServlet1extendsHttpServlet{publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{response.setContentType(text/html);PrintWriterout=response.getWriter();Stringaa=request.getQueryString();Stringbb=request.getMethod();out.println(aa);out.println(bb);}}把Servlet1.class文件放在Web服务器适合的目录下,在浏览B器地址栏内输入:http://localhost:8080/servlet/Servlet1?name=jb-aptechphone=12345678,看到的结果是()。A.name=jb-aptechphone=12345678GETB.name=jb-aptech,phone=12345678GETC.jb-aptech,12345678POSTD.name,phoneGETE.2,POST
考题
在J2EE中,有如下代码在Servlet1.java中。importjavax.servlet.*;importjavax.servlet.http.*;importjava.io.IOException;importjava.io.PrintWriter;publicclassServlet1extendsHttpServlet{publicvoidinit()throwsServletException{}publicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{PrintWriterout=response.getWriter();out.println(hello!);}}假如编译Servlet要具备的环境都已经建立好。现在用完全正确的命令编译该文件,对于以下陈述正确的是()。A.编译该文件时会提示缺少doGet()或者doPost()方法,编译不能够成功通过B.编译后,把Servlet1.class放在正确位置,在浏览器中查看该Servlet1,会看到输出文字:“hello!”C.编译后,把Servlet1.class放在正确位置,在浏览器中查看该Servlet1,却看不到任何输出的文字D.编译后,把Servlet1.class放在正确位置,在浏览器中查看该Servlet1,却看到产生运行时错误的出错信息
考题
在J2EE中,有如下代码在Servlet1.java中Importjavax.servlet.*;Importjavax,servlet.http.*;Importjava.io,IOException;Importjava.io.PrintWriter;PublicclassServlet1extendsHttpServlet{Publicvoidinit()throwsServletException{}Publicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{PrintWriterout=reponse.getWriter();Out.println(hello!);}}假如要编译的环境已都已经搭建好。现在用完全正确的命令编译该文件,对于以下陈述正确的是();A.编译文件时会提醒缺少doGet和doPost方法,编译不能成功通过B.编译后,把Servlet.Class放在正确的位置,在浏览器查看该Servlet会看到输出文字:“hello”C.编译后,把Servlet.Class放在正确的位置,在浏览器查看该Servlet却看不到任何文字D.编译后,把Servlet.Class放在正确的位置,在浏览器查看该Servlet会却看到运行时的错误信息
考题
在j2ee中,有如下代码在servlet1.java中Importantjavax.servelt.*;Importantjavax.servlet.http.*Importjava.io.ioexceptionImportjava.io.printwriterPublicclassservlet1extendshttpservlet{Publicvoidinit()throwsserveltexception{}Publicvoidservice(httpserveltrequestrequest,httpserbletresponseresponse)throwsservletexception,ioexception{Printwriterout=response.getwriter();Out.println(hello”);}}假如编译serblet要具备的环境都已经建立好,现在用完全正确的命令编译该文件,对于以下陈述正确的是()A.编译该文件时会提示缺少doget()或者dopost()方法,编译不能够成功通过B.编译后,把servlet1.class放在正确位置,在浏览器中查看该servlet1,会看到输出文字:“hello”C.编译后,把servlet1.class放在正确位置,在浏览器中查看该servlet1,却看不到任何输出的文字D.编译后,把servlet1.class放在正确位置,在浏览器中查看该servlet1,却看到产生运行时错误的出差信息
考题
在J2EE中,有如下代码在Servlet1.Java中Importjavax.servlet.*;Importjavax.servlet.http.*Importjava.io.IOException;Importjava.io.PrintWriter;PublicclassServlet1extendsHttpServlet{Publicvoidinit()throwServletException{}Publicvoidservice(HttpServletRequestrequest,HttpServletResponceresponse)throwsServletException,IOException{PrintWriterout=response.getWriter();Out.println(hello!”);}}假如编译Servlet要具备的环境都已经建立好。现在用完全正确的命令编译该文件,对于以下成熟正确的是()A.编译该晚间时会提示缺少doGe()t或者doPost(),编译不能够成功通过B.编译后,把Serlvet.cass放在正确的位置,在浏览器中查看该Servlet1,会看到输出文在:“hello!”C.编译后,把Servlet.class放在正确的位置,在浏览器中查看该Servlet1,却看不到任何输出的文字D.编译后,把Servlet.class放在正确的位置,在浏览器中查看该Servlet1,却看到产生运行时错误的出错信息
考题
在J2EE中,在Servlet1中的doGet和doPost方法中只有如下代码:request.setAttribute(jb,aptech);response.sendRedirect(http://localhost:8080/servlet/Servlet2);那么在Servlet2中使用()可以把属性jb的值取出来。
A.Stringstr=request.getAttribute(jb);B.Stringstr=(String)request.getAttribute(jb);C.Objectstr=request.getAttribute(jb);D.取不出来
考题
在J2EE中,给定某Servlet的代码如下,编译运行该文件,以下陈述正确的是( )public class Servletl extends HttpServlet{public void init() throws ServletException{}public void service(HttpServletRequestrequest,HttpServletResponse response)throwsServletException,IOException{PrintWriter ut=response.getWriter();out.println(“hello!”);}}A、编译该文件时会提示缺少doGet()或者doPost()方法,编译不能够成功通过B、编译后,把Servletl.class放在正确位置,运行该Servlet,在浏览器中会看到输出文字:hello!C、编译后,把Servletl.class放在正确位置,运行该Servlet,在浏览器中会看不到任何输出的文字D、编译后, 把Servletl.class放在正确位置,运行该Servlet,在浏览器中会看到运行期错误信息
考题
给定某servlet 程序的片段,如下:Public void doGet(HttpServletRequestrequest,Httpservletresponse response){_________}要把session的失效时间设为30分钟,应该在下划线处插入( )A、request.getSession().setTimeout(1800);B、request.getSession().setTimeout(30)C、request.getSession().setMaxInactiveInterval(1800);D、request.getSession().setMaxInactiveInterval(30);
考题
Servlet的基本架构public class ServletName extends HttpServlet {public void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {}public void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {}}1、用String的方法将数据类型转换为String。
考题
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);
考题
下面哪个方法不是HttpServlet类:()A、protected void doGet(HttpServletRequest reg,HttpServletResponse res) throws Servlet Exception ,java.io.IOExceptionB、protected void doPost(HttpServletRequest reg,HttpServletResponse res) throws Servlet Exception,java.io.IOExceptionC、protected void doHead(HttpServletRequest reg,HttpServletResponse res) throws Servlet Exception,java.io.IOExceptionD、protected void doReceive(HttpServletRequest reg,HttpServletResponse res) throws ServletException,java.io.IOException
考题
在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,却看到产生运行时错误的出错信息
考题
Which two prevent a servlet from handling requests.?()A、 The servlet’s init method returns a non-zero status.B、 The servlet’s init method throws a Servlet ExceptionC、 The servlet’s init method sets the Servlet Response’s context length to 0D、 The servlet’s init method sets the Servlet Response’s content type to null.E、 The servlet’s init method does NOT return within a time period defined by the servlet container.
考题
在J2EE中,有如下代码在Servlet1.java中。 importjavax.servlet.*; importjavax.servlet.http.*; importjava.io.IOException; importjava.io.PrintWriter; publicclassServlet1extendsHttpServlet{publicvoidinit()throwsServletException{} publicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ PrintWriterout=response.getWriter(); out.println("hello!");}} 假如编译Servlet要具备的环境都已经建立好。现在用完全正确的命令编译该文件,对于以下陈述正确的是()。A、编译该文件时会提示缺少doGet()或者doPost()方法,编译不能够成功通过B、编译后,把Servlet1.class放在正确位置,在浏览器中查看该Servlet1,会看到输出文字:“hello!”C、编译后,把Servlet1.class放在正确位置,在浏览器中查看该Servlet1,却看不到任何输出的文字D、编译后,把Servlet1.class放在正确位置,在浏览器中查看该Servlet1,却看到产生运行时错误的出错信息
考题
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);
考题
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"))
考题
单选题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);
考题
单选题在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,却看到产生运行时错误的出错信息
考题
单选题在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,却看到产生运行时错误的出差信息
考题
单选题在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,却看到产生运行时错误的出错信息
考题
单选题在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会却看到运行时的错误信息
考题
单选题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);
考题
单选题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);
考题
单选题在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-aptechphone=12345678,看到的结果是()。A
name=jb-aptechphone=12345678 GETB
name=jb-aptech,phone=12345678 GETC
jb-aptech,12345678 POSTD
name,phone GETE
2,POST
考题
多选题Which two prevent a servlet from handling requests.?()AThe servlet’s init method returns a non-zero status.BThe servlet’s init method throws a Servlet ExceptionCThe servlet’s init method sets the Servlet Response’s context length to 0DThe servlet’s init method sets the Servlet Response’s content type to null.EThe servlet’s init method does NOT return within a time period defined by the servlet container.
考题
单选题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.
热门标签
最新试卷