题目内容

Servlet的service(),在servlet的生命周期中执行的次数( )

A. 仅1次
B. 每一个会话,执行一次
C. 每一个请求,执行一次
D. 0次

查看答案
更多问题

当服务器关闭时,servlet调用下面( )方法,销毁servlet。

A. service()
B. init()
C. doPost()
D. destroy()

现定义有一servlet:Number,代码如下。servlet 代码:@WebServlet("/ShowNumber")public class ShowNumber extends HttpServlet {public void service(HttpServletRequest req, HttpServletResponse resp)throws IOException {resp.setContentType("text/html;charset=GBK");PrintWriter out = resp.getWriter();int sum=0;int num=Integer.parseInt(req.getParameter("num"));out.println("");if (num%2==0) {for (int i=0;i<=num;i++) {out.print(i+" ");sum=sum+i;}out.println(sum);} else {for (int i=0;i<=num;i++) {out.print(i+" ");}}out.println("
");out.println("");}}如果在浏览器地址栏内输入请求:http://localhost:8080/Test/ShowNumber?num=3, 则浏览器显示结果( )

A. 0 1 2 3 6
B. 0 1 2 3
C. 1 2 3
D. 1 2 3 6

现定义有一servlet:Number,代码如下。servlet 代码:@WebServlet("/ShowNumber")public class ShowNumber extends HttpServlet {public void service(HttpServletRequest req, HttpServletResponse resp)throws IOException {resp.setContentType("text/html;charset=GBK");PrintWriter out = resp.getWriter();int sum=0;int num=Integer.parseInt(req.getParameter("num"));out.println("");if (num%2==0) {for (int i=0;i<=num;i++) {out.print(i+" ");sum=sum+i;}out.println(sum);} else {for (int i=0;i<=num;i++) {out.print(i+" ");}}out.println("
");out.println("");}}在浏览器地址栏内输入请求:http://localhost:8080/Test/ShowNumber?num=4, 则浏览器显示结果:( )

A. 0 1 2 3 4 10
B. 0 1 2 3 4
C. 1 2 3 4 10
D. 1 2 3 4

假设在myServlet应用中有一个MyServlet类,在web文件中对其进行如下配置myservlethaut.servlet.MyServletmyservlet/welcome下列可以访问到Servlet是()

A. http://localhost:8080/MyServlet
B. http://localhost:8080/mservlet
C. http://localhost:8080/haut/servlet/MyServlet
D. http://localhost:8080/welcome

答案查题题库