现定义有一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
当一个请求到达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