题目内容

当一个请求到达servlet时,响应用户的请求,下列方法一定会调用的方法是()。

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

查看答案
更多问题

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

A. 0 3 6 9 sum=18
B. 0 3 6 9
C. 1 3 5 7 9 sum=25
D. 1 3 5 7 9

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

A. 0 3 6 9 sum=18
B. 0 3 6 9
C. 1 3 5 7 9 sum=25
D. 1 3 5 7 9

位于web服务目录下的index.jsp文件,通过表单请求myservlet.control.MajorHandler,其表单如下
......,change________①__________________change__________②_________在servlet应配置中,①应为( )

A. MajorHandler
B. MajorHandler.calss
C. myservlet.control.MajorHandler
D. myservlet.control.MajorHandler.class

位于web服务目录下的index.jsp文件,通过表单请求myservlet.control.MajorHandler,其表单如下......,change________①__________________change__________②_________在servlet应配置中,②应配置为( )

A. change
B. /change
C. majorChange
D. / majorChange

答案查题题库